Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract from file

Status
Not open for further replies.

tini1208

Technical User
Feb 13, 2006
56
DE
hi all,

i want to extract several lines (the lines are more than one time in the file) from a file. the input looks like:

i_AttFlg1 = 16 16 16 16
i_lat = 50764695 50826421 50888144 50949866
i_lon = 95795766 95780813 95765832 95750822
i_OrbFlg = 0 0
0 0
0 0
0 0
i_spare1 = 0 0 0 0
i_LidarQF = 2 2 2 2
i_spare2 = 0 0 0 0 0 0 0 0
i_topo_elev = 0 0 0 0
i_atm_dem = 1442 1279 1315 1212
i_LRcld_bot = 32767 32767 32767 32767 32767 32767 32767
32767 32767 32767
i_LRcld_top = 32767 32767 32767 32767 32767 32767 32767
32767 32767 32767
i_LRcld_grd = 32767
i_spare3 = 0 0
i_MRcld_bot = 32767 32767 32767 32767 32767 32767 32767
32767 32767 32767
32767 32767 32767 32767 32767 32767 32767 32767 32767 32767
32767 32767 32767 32767 32767 32767 32767 32767 32767 32767
32767 32767 32767 32767 32767 32767 32767 32767 32767 32767
i_MRcld_top = 32767 32767 32767 32767 32767 32767 32767
32767 32767 32767
32767 32767 32767 32767 32767 32767 32767 32767 32767 32767
32767 32767 32767 32767 32767 32767 32767 32767 32767 32767
32767 32767 32767 32767 32767 32767 32767 32767 32767 32767

the goal is, to extract lines out of this input to an output file, for example:

i_lat
i_lon
i_MR_cld_bot
i_MR_cld_top

in case of i_MR_cld_bot and i_MR_cld_top i want to get the following lines, which belong to the variable.
i hope my explanation is comprehensible?!

please....can anybody help me??
 
Hi

No, there is no need for BEGIN block.

If you put it just as is in a file called script.awk :
Code:
awk -f script.awk /input/file
If you add a shebang at the begining of the file :
Code:
script.awk /input/file
Note, that the shebang should include the -f option too, but without file name, and the file should have execute permission.
Code:
#!/usr/bin/awk -f

/^i_ElvuseFlg/ {
[gray]# ...[/gray]
}

Feherke.
 
hello,

i copied the skript in a file and tried to run it. then i get the following errors but i don't understand what is wrong.

awk: syntax error near line 5
awk: illegal statement near line 5
awk: syntax error near line 6
awk: illegal statement near line 6
awk: syntax error near line 8
awk: bailing out near line 8

cheers
 
Hi

And how you put it in the file ? With or without shebang ? Just to can guess which could be lines 5, 6 and 8.

There are only standard commands and anyway, I tried it with [tt]gawk[/tt], [tt]gawk[/tt] with --traditional option and [tt]mawk[/tt]. And works fine.

One more thing to make it nicer, is to put the [tt]?:[/tt] expression in paranthesis ( () ). But this should not change it.
Code:
[gray]# ...[/gray]
for (i=[red]([/red]ind==0?3:1[red])[/red];i<=NF;i++) Elv[++ind]=$i
[gray]# ...[/gray]

Feherke.
 
hi,

this is the hole file:

#!/usr/bin/awk -f

/^i_ElvuseFlg/ {
ind=0
do {
for (i=ind==0?3:1;i<=NF;i++) Elv[++ind]=$i
if (getline!=1) break
} while (!/^i_/)
for (i=1;i in Elv;i++) print i,Elv
}

i'm not using gawk etc. ....is this maybe a problem?

cheers
 
Hi

tini1208 said:
i'm not using gawk etc. ....is this maybe a problem?
No, should not be. The [tt]mawk[/tt] I also tried is a pretty simple implementation. If works with that, should work with others to. Maybe excepting some [tt]awk[/tt]s for Windows.

By the way. What is exactly your [tt]awk[/tt] and your operating system ? ( Usually [tt]awk[/tt]s prints their version with -W version option. ) A have
- GNU Awk 3.1.1
- mawk 1.3.3 Nov 1996
on Linux.

Feherke.
 
hi,

i'm using the gnu awk...on exceed (windows to unix).
i tried it some more times, but it doesn't work...always the same error.

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top