Awk & sed query for output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk & sed query for output
# 1  
Old 09-01-2010
Awk & sed query for output

Hello,

I have a file. its content are like below.
Code:
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:--
Code:
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!!

Last edited by Franklin52; 09-01-2010 at 04:24 AM.. Reason: Please use code tags!
# 2  
Old 09-01-2010
Try this:
Code:
awk '{printf("%s%s",$0,NR%3?"\t":RS)}' file

# 3  
Old 09-01-2010
Quote:
Originally Posted by Franklin52
Try this:
Code:
awk '{printf("%s%s",$0,NR%3?"\t":RS)}' file


i replaced awk with nawk then it is working.Can you please explain it
# 4  
Old 09-01-2010
Quote:
Originally Posted by malikshahid85
i replaced awk with nawk then it is working.Can you please explain it
Code:
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.

Last edited by Franklin52; 09-01-2010 at 06:45 AM.. Reason: typo
This User Gave Thanks to Franklin52 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Different output for awk command on Linux & HP-UX

I am using an awk command to extract a particular portion of a string. Below is the command and its output on a Linux system: oracle@host1:/tmp (/home/oracle) $uname -a Linux host1 2.6.32-279.39.1.el6.x86_64 #1 SMP Fri Nov 15 05:38:26 EST 2013 x86_64 x86_64 x86_64 GNU/Linux ... (7 Replies)
Discussion started by: veeresh_15
7 Replies

2. Shell Programming and Scripting

SQL query output convert to HTML & send as email body

Hi , I have a sql query in the unix script ,whose output is shown below.I want to convert this output to HTML table format & send email from unix with this table as email body. p_id src_system amount 1 A 100 2 B 200 3 C ... (3 Replies)
Discussion started by: jagadeeshn04
3 Replies

3. Shell Programming and Scripting

Trim sed output & assign to variable

Hi, I have the following command that parses an xml file to read a node <port>'s value. Hoever the output comes with spaces. My requirement is to trim the spaces around the value and assign to a variable. sed -n 's|<port>\(.*\)</port>|\1|p' ../cfg.xml How do I go about it? (6 Replies)
Discussion started by: sai2013
6 Replies

4. Shell Programming and Scripting

Grep & sed - Output

Hi All, Facing an issue with grep & sed I have logs as below: gsc_1_20121121.log:2012-11-21 10:09:13,143 INFO - fmsspace.1 ProcessNewOrderSingleRequest: Result - ProcessNewOrderSingleBatchResultDTO - success:true,newOrderSingleBatchResults:ProcessNewOrderSingleResultDTO -... (13 Replies)
Discussion started by: irfanmemon
13 Replies

5. Shell Programming and Scripting

Want to sort a file using awk & sed to get required output

Hi All, Need Suggestion, Want to sort a file using awk & sed to get required, output as below, such that each LUN shows correct WWPN and FA port Numbers correctly: Required output: 01FB 10000000c97843a2 8C 0 01FB 10000000c96fb279 9C 0 22AF 10000000c97843a2 8C 0 22AF 10000000c975adbd ... (10 Replies)
Discussion started by: aix_admin_007
10 Replies

6. Shell Programming and Scripting

sed & remove duplicates on output

sed -e '1d' -e 's/^\(]\{2\}\)-\(]\{3\}\)-\(]\{4\}\).*/"0000020\1\200\3"\,/g' abc.txt This script returns many duplicates due to the duplciates in the .txt file. i.e. ... "000002012149000060", "000002012149000064", "000002012149000064", "000002012149000064", "000002012149000064",... (9 Replies)
Discussion started by: Daniel Gate
9 Replies

7. Shell Programming and Scripting

sed or awk query

I have a set of multiple files out of which one i am showing below : A0120110124102329 BED. B01***DETALLADA 43984 The BO1 is the starting pattern of the second line. In the 2nd line in position 30,31,32 i need to replace 111, instead of 3... (2 Replies)
Discussion started by: dazdseg
2 Replies

8. Solaris

awk output query

Hi Everyone, When i issue command like ls -l | awk '/udtts/ {print $9}' =============================== I am getting output as udttsGEHLNAR.6864 udttsGEHLNAR.7921 udttsNARALAX.15415 udttsNARALAX.18016 But I want output after dot i.e like 6864 7921 15415 18016 (3 Replies)
Discussion started by: gehlnar
3 Replies

9. Shell Programming and Scripting

sed & awk

Hi. I'm going to learn scripting and i have the following topics on the list: sed, awk, shell scripting, perl. My question is, whehter i should learn sed and awk? Aren't this tools outdated? Although i see that GNU upgrade it's versions of these tools from time to time. And, the next... (9 Replies)
Discussion started by: kukuruku
9 Replies

10. Shell Programming and Scripting

HTTP Query Request & Parsing returned XML output

I have a PERL script from which I need to make a HTTP request to Web Servlet (Essentially a URL with variables and values like &Variable1=AAAAAA&Variable2=BBBBBBBBB&Variable3=CCCCCCC). The Web servlet returns an XML result which needs to be parsed for the contents of the result within the program.... (15 Replies)
Discussion started by: jerardfjay
15 Replies
Login or Register to Ask a Question