Hi -
I have a file with contents as below.
12.1 a.txt
12.1 b.txt
12.1 c.txt
13.2 a.txt
13.2 d.txt
14.3 f.txt
15.4 a.txt
15.4 b.txt
15.4 z.txt
I need to print the contents like this.
12.1 a.txt
< >< >< >b.txt
< >< >< >c.txt
13.2 a.txt
< >< >< >d.txt
14.3 f.txt
15.4 a.txt
< >< >< >b.txt
< >< >< >z.txt
I think this can be done using awk. Any suggeestions please? Thanks in advance.
Something like this?
awk 's==$1{print "< >< >< >" $2;next}{s=$1;print}' file
Regards
Thanks Franklin... It works.. But. in < > place I need tab character. I tried. but with three or more lines and still I could not be successful.
If possible can you explain the code too! It is single line and almost it does my work perfectly. I wrote seven line code. [:(]
Thanks a lot.
awk 's==$1{printf("\t\t\t%s\n", $2);next}{s=$1;print}' file
regards
Superb... It's great. I got it.... Thanks a lot your timely help Franklin
that works.. how does it know which line to skip?
Explanation:
s==$1{printf("\t\t\t%s\n", $2);next}
If the variable s is equal to the first field, print 3 tabs before the 2nd field and read the next line.
{s=$1;print}
If the variable s is not equal to the first field, we have a new line. Store the value of 1st field in s and print the whole line.
Regards