Insert specific line when found similar value

Hi All,

I have file like this:

file1:

3778 10474 24
3778 10475 24
3778 10476 25
3778 10495 26
3794 10001 33
3794 10002 33
3794 10004 33
3794 10007 34
3794 10008 34
3794 10011 34
3794 10012 34
3794 10013 34
3794 10017 34
3810 10282 27
3810 10283 27
3810 10284 27
3810 10285 27
3810 10286 27
3810 10287 27
3810 10288 27
3906 10154 34
3906 10155 34
3906 10156 34
3906 10157 34

output that I want :

                              LINE  3778 ,
                              10474 =  24 ,
                              10475 =  24 ,
                              10476 =  25 ,
                              10495 =  26 ,
                              LINE  3794 ,
                              10001 =  33 ,
                              10002 =  33 ,
                              10004 =  33 ,
                              10007 =  34 ,
                              10008 =  34 ,
                              10011 =  34 ,
                              10012 =  34 ,
                              10013 =  34 ,
                              10017 =  34 ,  
                              LINE  3794 ,
                              10282 =  27 ,
                              10283 =  27 ,
                              10284 =  27 ,
                              10285 =  27 ,
                              10286 =  27 ,
                              10287 =  27 ,
                              10288 =  27 ,
                              LINE  3906 ,
                              10154 =  34 ,
                              10155 =  34 ,
                              10156 =  34 ,
                              10157 =  34 ,

Thanks in advance

  • Attila

Hi

$ awk 'x!=$1{print "LINE ",$1,",";x=$1}{ print $2," = ",$2," ,";}' file1

Guru.

1 Like

Nice code guru.

But it needs a small correction

1 Like

my mistake...thanks itkamaraj

Guru.

above awk command will not work for the below input. ( it only works on sorted data )

so, if you have data's like below, sort it before apply the awk. ( sort -n )

 
3778 10474 24
3778 10475 24
3778 10476 25
3778 10495 26
3794 10001 33
3794 10002 33
3778 10495 26

I just little edit like this:

awk 'x!=$1{print "                              LINE ",$1,",";x=$1}{print "                             " ,$2," = ",$3," ,";}' file1 > file2

Solved, Thank you all.

awk '{printf "\t\t\t\t%s  ,\n", a[$1]++?$2 "  =  " $3:"LINE  " $1}' file1