Converting a line into a list using awk or sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting a line into a list using awk or sed
# 1  
Old 12-20-2011
Converting a line into a list using awk or sed

Hello,

I am trying to convert a line into a list using awk or sed.

Code:
 
Line:
345 897 567 098 123
 
output:
345 
897 
567 
098 
123

thanks
# 2  
Old 12-20-2011
Code:
echo "345 897 567 098 123" | sed 's/ /\n/g'

Code:
echo "345 897 567 098 123" | tr ' ' '\n'

Code:
echo "345 897 567 098 123" | awk '{for(i=1;i<=NF;i++) {print $i}}'

Did you try searching the forum? There're lots of similar posts:
https://www.unix.com/unix-dummies-que...-one-line.html
https://www.unix.com/shell-programmin...-one-line.html
https://www.unix.com/unix-dummies-que...line-unix.html
https://www.unix.com/unix-advanced-ex...pped-file.html

Last edited by balajesuri; 12-20-2011 at 05:21 AM..
This User Gave Thanks to balajesuri For This Post:
# 3  
Old 12-20-2011
In nawk if missed ..
Code:
$ nawk '{gsub(/ /,"\n")};1' infile

This User Gave Thanks to jayan_jay For This Post:
# 4  
Old 12-20-2011
Code:
echo "12 11 13 15" | awk 'BEGIN { RS=" "; ORS=" \n"; } {print$1; } '

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 12-20-2011 at 05:25 AM..
This User Gave Thanks to sathish92 For This Post:
# 5  
Old 12-20-2011
How could we forget Perl!
Code:
echo "345 897 567 098 123" | perl -pe 's/ /\n/g'

This User Gave Thanks to balajesuri For This Post:
# 6  
Old 12-20-2011
And another one:

Code:
% printf '%s\n' 345 897 567 098 123 
345
897
567
098
123

# 7  
Old 12-20-2011
Hey guys thanks all of you.

tried all and the all work.

and I did try to search but did not find the links you provided
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. Shell Programming and Scripting

Search from a line to end of list using sed

Dear Unix Experts :), Below is a small section of a large file with the following list: 1. Starts with string " interest" as the heading 2. Followed by a list of activities 3. Ends with a blank line before starting with another different list. E.g. Sporting interest football... (13 Replies)
Discussion started by: gjackson123
13 Replies

4. Shell Programming and Scripting

Scraping line - Using awk or sed

Hello, Can somone help with this command please? I have this output pattern in a file. I use a simple awk command to print each field separated by comma. For example I use this to get the first awk -F, "{ print $1 }" "ABC=abcdefg,CDF=mnqrst,GGG=hrvyess" issue: What I... (7 Replies)
Discussion started by: mnassiri
7 Replies

5. Shell Programming and Scripting

Get the list with sed or awk

#cat file aa bb cc dd ee 77 dd gg xx I want to get: when VAR="zzz D" get below out put (7 Replies)
Discussion started by: yanglei_fage
7 Replies

6. Shell Programming and Scripting

Converting txt file into CSV using awk or sed

Hello folks I have a txt file of information about journal articles from different fields. I need to convert this information into a format that is easier for computers to manipulate for some research that I'm doing on how articles are cited. The file has some header information and then details... (8 Replies)
Discussion started by: ksk
8 Replies

7. Shell Programming and Scripting

awk;sed appending line to previous line....

I know this has been asked before but I just can't parse the syntax as explained. I have a set of files that has user information spread out over two lines that I wish to merge into one: User1NameLast User1NameFirst User1Address E-Mail:User1email User2NameLast User2NameFirst User2Address... (11 Replies)
Discussion started by: walkerwheeler
11 Replies

8. Shell Programming and Scripting

Read logline line by line with awk/sed

Hello, I have a logfile which is in this format: 1211667249500#3265 1211667266687#2875 1211667270781#1828 Is there a way to read the logfile line by line every time I execute the code and put the two numbers in the line in two separate variables? Something like: 1211667249500#3265... (7 Replies)
Discussion started by: dejavu88
7 Replies

9. Shell Programming and Scripting

Number a list at end of line using 'sed'

Hi All I have a script which has produced a list, I have used 'sed' to number my list, but i want to list at end of line with the first line starting at zero (0) and brackets round it ie My List i want Hello (0) this (1) day (2) can (3) be (4) sed '/./=' filename | sed '/./N; s/\n/) /'... (5 Replies)
Discussion started by: chassis
5 Replies

10. UNIX for Dummies Questions & Answers

converting a list into a line

Hi, this is a pretty intersting problem, I would like to convert a list of words into a concatenated string of words with whitespace between each word. e.g file list :- hello how are you today convert into hello how are you today. What command would I use to do this? Thanks (2 Replies)
Discussion started by: zulander
2 Replies
Login or Register to Ask a Question