awk to print in a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to print in a line
# 1  
Old 12-17-2010
awk to print in a line

hi all,
i have text file with sample text
Code:
01                    
02        
 .. abc 
    
 .. def 
    
 .. xyz 
 .. x12 
03                    
04                    
    
    
 .. z123 
    
    
 .. x234 
    
    
 .. 2323

out put i am looking
Code:
01
02 abc,def,xyx,x12
03
04 z123,x234,2323

Thanks

Last edited by Scott; 12-17-2010 at 03:01 PM.. Reason: Code tags
# 2  
Old 12-17-2010
What do the ".." stand for ?
1 word ?
more ?
Please post a full representative sample, not just a "kind of" sample.
The more precise a question is, the more precise the answer can be
# 3  
Old 12-17-2010
sorry for that

i want the values between the numbers

anything starting with .. has come with its associated number above it as comma separated

for
01
02 (abc,def,xyz,x12)
03
04 (z123 ,x234,2323)
# 4  
Old 12-17-2010
you mean your input files looks like :
Code:
01
02
02 abc
02 def
02 xyz
02 x12
03
04
04 z123
04 x234
04 2323

? or does it look another way ??
# 5  
Old 12-17-2010
no sample i gave is exact
Code:
01
02
 abc

 def

 xyz
 x12
03
04


 z123


 x234




 2323

".." previous thing i removed

---------- Post updated at 01:59 PM ---------- Previous update was at 01:33 PM ----------

sorry for giving half info so far

my sample data looks like this
Code:
21
### W dcf 
               ### Wdcf HD 
             350                   
351                   
353                   
### abc Plus 
     36                    
###  abc 2 WEST 
         ###  abc xyzZONE     
###  abc NEXT            
###  abc  abcCASE WEST   
###  abc WEST 
           ###  abc WOMEN           
###  abcTIME

so the out put i am looking is
Code:
21 (W dcf,Wdcf HD)
350
351
353 (abc Plus)
36 (abc 2 WEST,abc xyzZONE,abc NEXT,abc  abcCASE WEST,abc WEST,abcTIME )


Last edited by Scott; 12-17-2010 at 03:03 PM.. Reason: Code tags, please...
# 6  
Old 12-17-2010
This may help. Looks quite ugly. Others may give better sol.
Code:
 
sed -e 's/^\(.*\)\(###\)\(.*\)/\2\3/g' -e 's/^\([^#0-9]*\)\([0-9[0-9]*\)/\2/g' inputFile | awk '/^[0-9][0-9]*/{if(b=!""){print b;b="";}b=$0;next;} /###/{b=b ", " $0} END {if(b!="") print b}' | sed -e 's/###//g' -e 's/^\([0-9][0-9]*\),\(.*\)/\1 (\2 )/'

# 7  
Old 12-17-2010
Would be ok if the output order doesn't matter :
Code:
sed 's/\s*###\s*//;s/^\s*//' infile | awk  '/^\s*$/{next}!/^[0-9][0-9]*/{B[x]=B[x]?B[x]","$0:$0}/^[0-9][0-9]*/{x=$1;A[$1]=$1" "}END{for(i in A)print A[i],(B[i])?"(":"",B[i],(B[i])?")":""}' OFS=''

Code:
# sed 's/\s*###\s*//;s/^\s*//;s/\s\s*/ /g' infile | awk '/^[0-9][0-9]*/{x=$1;A[$1]=$1" "}!/^[0-9][0-9]*/{B[x]=B[x]?B[x]","$0:$0}END{for(i in A)print A[i],(B[i])?"(":"",B[i],(B[i])?")":""}' OFS=''
36 (abc 2 WEST ,abc xyzZONE ,abc NEXT ,abc abcCASE WEST ,abc WEST ,abc WOMEN ,abcTIME)
350
351
353 (abc Plus )
21 (W dcf ,Wdcf HD )


Last edited by ctsgnb; 12-17-2010 at 04:39 PM..
This User Gave Thanks to ctsgnb 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

awk to print the line that matches and the next if line is wrapped

I have a file and when I match the word "initiators" in the first column I need to be able to print the rest of the columns in that row. This is fine for the most part but on occasion the "initiators" line gets wrapped to the next line. Here is a sample of the file. caw-enabled ... (3 Replies)
Discussion started by: kieranfoley
3 Replies

2. Shell Programming and Scripting

awk print everything in new line

Hi, I have the following file and I would like to print everything to new line and the field seperator should be the dash (-). /usr/java/jdk1.6.0_30/bin/java -Dprogram.name=run.sh -server -XX:PermSize=512m -XX:MaxPermSize=512m -XX:NewSize=1g -XX:MaxNewSize=1g -Xmx3g -Xms3g... (3 Replies)
Discussion started by: kmaq7621
3 Replies

3. Shell Programming and Scripting

awk script -print line when $2 > $2 of previous line

Hi all, From a while loop I am reading a sorted file where I want to print only the lines that have $1 match and $2 only when the difference from $2 from the previous line is > 30. Input would be like ... AN237 010 193019 0502 1 CSU Amoxycillin AN237 080 ... (2 Replies)
Discussion started by: gafoleyo73
2 Replies

4. UNIX for Dummies Questions & Answers

awk...print first line...

hello all, I am trying to use the AWK cmd on unix and trying to figre out how i can only print the first line and now rest of the line...so for example... $ lsnrctl version|grep Version| awk '{print $5}'| awk -F. '{print $1}'|uniq 11 NT Adapter for but i only want 11 to print out there... (3 Replies)
Discussion started by: abdul.irfan2
3 Replies

5. Shell Programming and Scripting

awk to print on the same line

Hi all, I've a script that uses awk to parse the output of wget during a database update. The code I use is: wget -c ftp://ftpsite/file 2>&1 | awk '/0%/ {print}'But this spits out each progress line on a new line: 37250K .......... .......... .......... .......... .......... 80% 10.9M 1s ... (2 Replies)
Discussion started by: euval
2 Replies

6. Shell Programming and Scripting

awk - print new line

Hi! Could you pls help me with my problem? My task is to find the longest line in several files - that's not the problem the problem is, I want command bellow to be stored in array, but one result per line: set line = (`cat $file | awk '{print NR, length, $0, "\n"}' | grep "^* $longest"`) the... (3 Replies)
Discussion started by: laco42
3 Replies

7. Shell Programming and Scripting

awk, Why does it print the same line twice?

awk '{print ; print '""'}' in.txt >inf.txt (2 Replies)
Discussion started by: cola
2 Replies

8. Shell Programming and Scripting

awk print the next line on the current line

Ok I have a file with hundreds of lines, four columns, space delimited, TESTB.TXT for example TESTB.TXT --- AA ZZ 12 34 BB YY 56 78 CC XX 91 23 DD VV 45 67 --- I want a new file that has 7 columns, the first four are identical, and the next 3 are the last three of the next line...so... (5 Replies)
Discussion started by: ajp7701
5 Replies

9. Shell Programming and Scripting

print any required line by its line no using awk and its NR variable

how to print any required line by its line no using awk and its NR variable for eg: ------------ 121343 adfdafd 21213sds dafadfe432 adf.adf%adf --------------- requied o/p if give num=3 it print: 21213sds -------------------------------------- (2 Replies)
Discussion started by: RahulJoshi
2 Replies

10. UNIX for Dummies Questions & Answers

awk print line

Hi All, I know that i can print the lines from awk just using the print method, but i need to print stuff before it i.e: BEGIN { i=0 } { i++ print i ")" print } END { } Here the output is: (7 Replies)
Discussion started by: Chiefos
7 Replies
Login or Register to Ask a Question