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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

complex modification file - awk ?

Status
Not open for further replies.

vlad9999

Programmer
Apr 19, 2010
23
FR
I have a file like this:

ident1 0ZZZ name1
ident1 1635 miscellaneous informations
ident1 1635 miscellaneous informations
ident1 9ZZZ

ident2 0ZZZ name2
ident2 1635 miscellaneous informations
ident2 1635 miscellaneous informations
ident2 1635 miscellaneous informations
ident2 9ZZZ

...

Each block consists of several lines identified with a code identifier on the first 7 characters, and each block begins
with a line ident1 0ZZZ name1 and ends with a line ident1 9ZZZ.

What I want? Just add after the code 1635 (always the same) namek value given in the first line of each block (name1, name2 ,...).

This should be possible with awk I suppose ... but how? I await your help, thank you ...
 
I confess I do not know, nor know how to find it..
 
Hi

Then probably it is an old standard [tt]awk[/tt]. Sorry, I never met such, so I have no idea about their issues.

Is your operating system Solaris ? Try to see if you have [tt]nawk[/tt]. That is an extended implementation.


Feherke.
 
Anyway this is beside the point, and then I have the solution to my problem.
This must be an old version of awk ...
..nawk behaves the same way..

 
I just tested using standard awk on Solaris 10, HP-UX 11.11 and AIX 6.1 and all of them accepted this fine:

Code:
$ echo "one\ntwo\nthree" | awk '{print}' -
one
two
three
$

What operating system are you using?

Annihilannic.
 
I concluded too quickly that only the first word is taken for the file passed with "|" + "-". In fact the problem is different. With file t1 and list_file yields:
Code:
t1:
one
two
three

list_file:
ident1
ident2

> cat t1 | awk '{print "NR="NR" FNR="FNR" "$0}' - list_file
NR=1 FNR=1 one
NR=2 FNR=1 two
NR=3 FNR=1 three
NR=4 FNR=1 ident1
NR=5 FNR=2 ident2
 
otherwise the station is an IBM - AIX, oslevel 5.3.0.0
 
then we waited (for the example with files t1, list_file):
Code:
NR=1 FNR=1 one
NR=2 FNR=[b][COLOR=red]2[/color][/b] two
NR=3 FNR=[b][COLOR=red]3[/color][/b] three
NR=4 FNR=1 ident1
NR=5 FNR=2 ident2
 
That is strange. Is it the same with nawk?

On Solaris the awk implementation is so old it doesn't even understand FNR, but nawk does.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top