Solved Moving and replacing columns

March 18, 2013 at 11:38:04
Specs: Windows Vista
Hi Guys ,

I have an file containing hundreds of line as per "ORIGINAL" below , I need to move the columns as per below , Appreciate if anyone can assist me with the commands .

Original :-
UST095: ChannelElementUl 384
UST095: ChannelElementDl 160
UST073: ChannelElementUl 384
UST073: ChannelElementDl 160
UST002: ChannelElementUl 384
UST002: ChannelElementDl 160

Example Change to :-
UST095 ChannelElementUl 384 ChannelElementDl 160
UST073 ChannelElementUl 384 ChannelElementDl 160
UST002 ChannelElementUl 384 ChannelElementDl 160

Thanks,
Roy


See More: Moving and replacing columns

Report •

#1
March 18, 2013 at 12:42:38
✔ Best Answer
Provided your data is sorted (and it looks like yours is in reverse order on field 1), this awk script should do the job. This is a break point report breaking on field 1:

#!/bin/ksh

awk '
{
gsub(":","",$1) # get rid of the colon in field 1
if(NR == 1)
   {
   printf("%s", $0)
   sf=$1
   next
   }
if (sf == $1)
   {
   $1=""
   printf("%s", $0)
   }
else
   { # terminate the previous line and start a new one
   printf("\n%s", $0)
   sf=$1
   }
}
END { printf("\n") }
' original.txt

# Let me know if you have any questions


Report •

#2
March 18, 2013 at 20:14:35
Well, thanks for sharing. I was searching quite same thing. Now it is solved.

Report •
Related Solutions


Ask Question