Awk & sed query for output

Hello,

I have a file. its content are like below.

mdn:87439842
imsi:23082038203
Ctime:12082010 01:20:10
mdn:9324783783
imsi:402349823322
Ctime: 12072010 01:20:10
mdn:87439842
imsi:23082038203
Ctime: 23072010 01:20:10
mdn:87439842
imsi:23082038203
Ctime:18072010 01:20:10
mdn:87439842
imsi:23082038203
Ctime:15072010 01:20:10

I want output like below:--

mdn:87439842	imsi:23082038203		Ctime:12082010 01:20:10
mdn:9324783783	imsi:402349823322	Ctime: 12072010 01:20:10
mdn:87439842	imsi:23082038203		Ctime: 23072010 01:20:10
mdn:87439842	imsi:23082038203		Ctime:18072010 01:20:10
mdn:87439842	imsi:23082038203		Ctime:15072010 01:20:10

I tried using awk ORS & NR & if loop but its not working out. Please help!!

I want 3 records in each line to be tab separated. Pls suggest!!

Try this:

awk '{printf("%s%s",$0,NR%3?"\t":RS)}' file

i replaced awk with nawk then it is working.Can you please explain it

awk '{printf("%s%s",$0,NR%3?"\t":RS)}' file

The command prints the line and a tab character if NR%3 != 0, otherwise it prints the line and a line feed.

If you aren't familiar with the mod operator %, google for modulo operator.

1 Like