Awk text processing

Hi Very much appreciate if somebody could give me a clue ..
I undestand that it could be done with awk but have a limited experience.

I have the following text in the file

1 909 YES NO
2 500 No NO
.
...

1 909 262 647
2 456 234 666
..
....

I need to present it in following form

1 909 YES NO 909 262 647
2 500 No NO 456 234 666

Basically join in one line text for 1,2 etc ...

Thanks in advance

try this.

 
$ cat fil1
1 909 YES NO
2 500 No NO
 
$ cat fil2
1 909 262 647
2 456 234 666
 
$ join fil1 fil2
1 909 YES NO 909 262 647
2 500 No NO 456 234 666
 
 

from the posting i think all the data are in a single file. using join fil1 fil2 is not possible unless you separate it into two different files. But is there an alternative without separating it into different files?

Will this work for you?

#> cat zam
1 909 YES NO
2 500 No NO



1 909 262 647
2 456 234 666


#> /usr/xpg4/bin/awk '{ x[$1] = x[$1]FS$2FS$3FS$4; } END { for (i in x) {print i x}}' zam
               
2 500 No NO 456 234 666
1 909 YES NO 909 262 647
awk '{a[$1]=a[$1] FS $2 FS $3 FS $4 } END {for (i in a) {print i, a}}' urfile

Similar solution, ignore my post.:slight_smile:

Thanks a lot - work wonders !!

One more Q on above if I may
I have customised , formated a bit above command (may be not perfect but Ok for me) and I wonder if I can print only if $3-$4 >0

cat tmp.lst|grep -v '#'|grep -v '-'|awk '{a[$1]=a[$1] FS $2" "$3" "$4} END {for (i in a) {print i, a[i]}}'\
|awk '{print $1" "$2" "$3" "$4" "$5}' >>tmp1.lst

I know I could have read docs but human nature ... looking for easy ways ..

Thanks again

---------- Post updated at 02:57 PM ---------- Previous update was at 02:42 PM ----------

No worries I figured it out... :slight_smile:
It turned out to be very easy

cat tmp.lst|grep -v '#'|grep -v '-'|awk '{a[$1]=a[$1] FS $2" "$3" "$4} END {for (i in a) {print i, a[i]}}'|awk '{if ($3>$4) print $1" "$2" "$3" "$4" "$5}'

Cheers

The first two pipes can be combined into one command.

awk '!/#/&& !/-/ {a[$1]=a[$1] FS $2" "$3" "$4} END {for (i in a) {print i, a}}' tmp.lst 

Not understand your last awk, seems $3>$4 should be changed to $6>$7

Thank you rdcwayx!
Yes will use it. Getting better and better at awk :slight_smile: . $3&$4 are correct as I removed 2 values from the original rows.
My final out put will look like below (but formatted propely)

      | PRIMARY | PHYSICAL STANDBY |

Thread Last Seq Gen Last Seq Rec Last Seq Applied Diff
----- ------------- ----------- ---------------- -----
1 1034 1034 262 772

Regards