awk until blank space and print next line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk until blank space and print next line
# 1  
Old 01-01-2012
awk until blank space and print next line

Hello and Happy New Year 2012!

I have this example:

Code:
1,2,3 4,5,6 7,8,9

For that, I'm trying to get:
Code:
1,2,3
4,5,6
7,8,9

for that, I think this might work but doesnt work so far:
Code:
awk '{for(i=1;i=NF;i++);sub(/\//,"",$i);print $i}' myfile

Any help is very grateful, thanks
# 2  
Old 01-01-2012
Hi,
Happy new year !

how about in sed:
Code:
echo "1,2,3 4,5,6 7,8,9" | sed 's/ /\n/g'

output:
Code:
1,2,3
4,5,6
7,8,9

or try this awk:

Code:
echo "1,2,3 4,5,6 7,8,9" | awk 'BEGIN { RS=" ";ORS="\n" }{print $0}'


Last edited by greet_sed; 01-01-2012 at 07:12 AM.. Reason: awk solution added
# 3  
Old 01-01-2012
Thank you so much greet_sed!! your codes are great! sed works fantastic!!!

Happy New Year to you!!
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 blank line between files

I have an AWK command that goes like this: awk '/from BOITE_AUX_LETTRES/,/end-procedure|END-PROCEDURE|end-select|END-SELECT/ {print FILENAME,FNR,$0}' *prp I get my results as follows: ZKELEXTV2.prp 16 from BOITE_AUX_LETTRES(#num_lettre) ZKELEXTV2.prp 23 LET $CONDEXTR = ' where... (2 Replies)
Discussion started by: mvalonso
2 Replies

2. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

3. Shell Programming and Scripting

Remove Space and blank line from file in UNIX shell script

I have below file. I want to remove space at begining of every line and then after also remove blank line from file. I use below code for each operation. sed -e 's/^*//' < check.txt > check1.txt sed '/^\s*$/d' < check1.txt > check2.txt above code not remove all the space... (12 Replies)
Discussion started by: Mohin Jain
12 Replies

4. Shell Programming and Scripting

Print lines between a regExp & a blank line

Hi, I have a file, say files_list, as below (o/p of ls -R cmd) $ cat files_list /remote/dir/path/to/file: sub-dir1 sub-dir2 sub-dir3 ... /remote/dir/path/to/file/sub-dir1: remote_file1.csv.tgz <blank line 1> /remote/dir/path/to/file/sub-dir2: remote_file2.csv.tgz <blank... (3 Replies)
Discussion started by: dips_ag
3 Replies

5. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line 98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

6. Shell Programming and Scripting

Print lines after the search string until blank line is found

All I want is to look for the pattern in the file...If I found it at # places... I want print lines after those pattern(line) until I find a blank line. Log EXAMPLE : MT:Exception caught The following Numbers were affected: 1234 2345 2346 Error java.lang.InternalError:... (3 Replies)
Discussion started by: prash184u
3 Replies

7. Shell Programming and Scripting

Unix help to find blank lines in a file and print numbers on that line

Hi, I would like to know how to solve one of my problems using expert unix commands. I have a file with occasional blank lines; for example; dertu frthu fghtu frtty frtgy frgtui frgtu ghrye frhutp frjuf I need to edit the file so that the file looks like this; (10 Replies)
Discussion started by: Lucky Ali
10 Replies

8. Solaris

deleting blank space in beginning of line in vi

How can we delete all the blank spaces in the beginning of some lines in a text in vi? Thanks, (2 Replies)
Discussion started by: Pouchie1
2 Replies

9. Shell Programming and Scripting

sed: print out to first blank line

I am trying to use wget and sed to extract a text based weather forecast for the Greater Victoria area only, this is one paragraph of many in a web page. I have tried /^$/ but that does not seem to work. So far I get mostly what I want with this: wget -qO -... (2 Replies)
Discussion started by: lagagnon
2 Replies

10. Shell Programming and Scripting

delete blank space in begining of line

Hi All, below is my data file file.txt $$0 ServerA LAN1 AAA IT01 04/30/2008 09:16:26 $$0 ServerB LAN1 AAA IT02 04/30/2008 09:16:26 here $ is a blank space how to delete first 2 blank spaces in a file. (4 Replies)
Discussion started by: karthikn7974
4 Replies
Login or Register to Ask a Question