awk script formatting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script formatting
# 1  
Old 11-25-2008
awk script formatting

Hello,
I have got the following kine in my script
awk '{printf("%s,", $0);next}{printf("%s", $0)}' ORS="," a.txt > b.out

The contents of b looks somewaht like this:
QUEUE(QUEUE1.Q),CURDEPTH(0),QUEUE(QUEUE2.Q),CURDEPTH(0),QUEUE(QUEUE3.Q),CURDEPTH(0)
But my desired output is :
QUEUE(QUEUE1.Q),CURDEPTH(0),
QUEUE(QUEUE2.Q),CURDEPTH(0),
QUEUE(QUEUE3.Q),CURDEPTH(0)
Not good with this awk thing.
Any idea folks.
Thanks in advance.
# 2  
Old 11-25-2008
Can you post your inputfile (a.txt)?

Regards
# 3  
Old 11-25-2008
Looks like this:

QUEUE(QUEUE1.Q)
CURDEPTH(0)
QUEUE(QUEUE2.Q)
CURDEPTH(0)
QUEUE(QUEUE3.Q)
CURDEPTH(0)
...
# 4  
Old 11-25-2008
Code:
awk '{ fmt=(!NR%2)?"%s,\n" :"%s,"; printf(fmt, $0) }' t.txt

# 5  
Old 11-25-2008
Getting a syntax error Smilie
# 6  
Old 11-25-2008
Try this:

Code:
awk 'NR%2{printf("%s,",$0);next}1' a.txt > b.out

# 7  
Old 11-25-2008
Same problem Smilie ... using a Sun OS 5.8 Solaris box ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Script Output in Outlook Formatting Issue

When i execute the below shell script with 2 different Input files, for one of the data files (datafile1) my email message body in the outlook messes up and every thing comes up in one line. May i please know what i am doing wrong here or how to fix this? The only difference in data files is one is... (1 Reply)
Discussion started by: Ariean
1 Replies

2. Shell Programming and Scripting

AWK/Shell script for formatting data in a file

Hi All, Need an urgent help to convert a unix file in to a particular format: **source file:** 1111111 2d2f2h2 3dfgsd3 ........... 1111111 <-- repeats in every nth line. remaining all lines will be different 123ss41 432ff45 ........... 1111111 <-- repetition qwe1234 123weq3... (1 Reply)
Discussion started by: rajivnairfis
1 Replies

3. UNIX for Dummies Questions & Answers

awk formatting

Hi all, I'm writing a simple awk code: awk 'BEGIN {FS="|"};{print "Type\tNumber\ttypes\tTotal";};{print $1, "\t", $2, "\t", $3, "\t", $4, "\t";}' db_query.txt it gives me the result: Type Number types Total XXX 498.0 5100.0 5274.661 Type Number types Total... (7 Replies)
Discussion started by: messi777
7 Replies

4. Shell Programming and Scripting

Formatting a report using awk

Our vendor produces a report that I would like to format in a particular way. Here is the sample output from their report: # AA.INDEX 2 11 2 239 52 (7,2) 07 MAY 11 203.1 55 # ACCOUNT 2 89561 2 ... (4 Replies)
Discussion started by: thaller
4 Replies

5. Shell Programming and Scripting

formatting awk

when i try this awk its giving out put as below. awk '!(/^$/||/--/||/selected/||/^ *$/){print $1}' tmp.txt output ===== 1 2010-08-03-12.31.26.126000 how excluede the 1st line ? i mean i want output only 2nd line i.e 2010-08-03-12.31.26.126000; (5 Replies)
Discussion started by: rocking77
5 Replies

6. Shell Programming and Scripting

AWK printing formatting help please

Hi all, Below is my testfile: COST,31-MAR-2011 01:01:04,31-MAR-2011 11:22:12,622 COST,21-MAR-2011 22:00:20,22-MAR-2011 11:07:23,788 FARE,23-MAR-2011 22:00:22,24-MAR-2011 10:10:46,731 FARE,02-MAR-2011 14:01:50,03-MAR-2011 08:30:54,1110 I need to append a number, for example 700, to the... (2 Replies)
Discussion started by: newbie_01
2 Replies

7. Shell Programming and Scripting

AWK formatting help.

Dear all I require help with AWK regarding this situation Input is : fn1 12345 fn1 23456 fn3 231513 fn1 22325 fn3 123125 Desired output is fn1 12345 23456 22325 fn3 231513 123125 (5 Replies)
Discussion started by: Peasant
5 Replies

8. Homework & Coursework Questions

Loosing formatting when echoing an awk script

1. The problem statement, all variables and given/known data: When I echo out the output of my awk script I loose the formatting that I set in my awk script (it should be in a table format). 2. Relevant commands, code, scripts, algorithms: 3. The attempts at a solution (include all... (2 Replies)
Discussion started by: ROFL
2 Replies

9. UNIX for Advanced & Expert Users

formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command. I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the the awk command statement shown here. Please help. ... (6 Replies)
Discussion started by: tekline
6 Replies

10. Shell Programming and Scripting

Formatting using awk

Let's say I write a simple script that contains the following: date | awk '{print $1}' date | awk '{print $2}' Of course, when I run the script the output will look similar to: Tue Mar What if I want my ouput to be on one line as follows: Tue Mar What changes would I need to... (2 Replies)
Discussion started by: cdunavent
2 Replies
Login or Register to Ask a Question