awk to change comma separated line to horizontal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to change comma separated line to horizontal
# 1  
Old 07-20-2015
awk to change comma separated line to horizontal

I am trying to change a file that looks like this:

Code:
file, announcement,date, server, server01, server02, server06, file04, rec01, rec04, rec03... etc

into a vertical file like this:

Code:
file
announcement
date 
server
server01
server02
server06

The file does not have to be sorted alphabetically. I tried a number of ways, but the comma is giving me trouble. Can someone suggest?

Last edited by vgersh99; 07-20-2015 at 12:42 PM.. Reason: code tags, please!
# 2  
Old 07-20-2015
Try
Code:
tr , '\n' <file

This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-20-2015
Hello newbie2010,

Could you please try following, please use code tags for commands/codes/inputs you are using in your posts too as per forum rules.
Code:
 awk '{gsub(/\, |\,/,"\n",$0);print}' Input_file

Thanks,
R. Singh
# 4  
Old 07-20-2015
a more detailed/granular sample input and the desired output would be helpful - a given mnemonic sample leaves room to interpretation......
# 5  
Old 07-20-2015
Code:
% perl -pe 's/\s?,\s?/\n/g' file.test
file
announcement
date
server
server01
server02
server06
file04
rec01
rec04
rec03... etc

# 6  
Old 07-20-2015
You could also try:
Code:
awk -F', *' '$1=$1' OFS='\n' file

which, with your sample input, produces the output:
Code:
announcement
date
server
server01
server02
server06
file04
rec01
rec04
rec03... etc

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

AIX put comma separated data on its own line

In Linux you can do this to put comma separated data on its own line like this. sed 's/ */&\n/g' /tmp/ports sed 's/ */\n/g' /tmp/ports How do you do this in AIX? It is not working. Is there another way to do this? Something like this. 1, 2, 3, 4 To look like this. 1 2 3 4 (4 Replies)
Discussion started by: cokedude
4 Replies

2. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

3. Shell Programming and Scripting

Combining multiple block of lines in one comma separated line

Hi Everyone, On my Linux box I have a text file having block of few lines and this block lines separated by one blank line. I would like to format and print these lines in such a way that this entire block of lines will come as single comma separated line & again next block of lines in next... (7 Replies)
Discussion started by: gr8_usk
7 Replies

4. Shell Programming and Scripting

Change the vertical logs to horizontal line

Hi, cat log EPC-SubsId: 3333 EPC-GrIds: RTGHUPA:1:15-11-2013T19:59,22-11-2013T19:59 EPC-GrIds: PrimaXGB_23:10 EPC-SubsId: 4444 EPC-GrIds: RTGHUPB:1:15-11-2013T19:59,22-11-2013T19:59 EPC-SubId: 5555 EPC-GrIds: RTGHUPC:1:15-11-2013T19:59,22-11-2013T19:59 EPC-SubsId: 6666... (1 Reply)
Discussion started by: justbow
1 Replies

5. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

6. Shell Programming and Scripting

Reading Words separated by comma in line

Hi All, I am facing issue, to read words in line, line as follow and i want to read word at each comma 1,you,are,two So i want read like 1 you are two Thanks (1 Reply)
Discussion started by: sujit_kashyap
1 Replies

7. Shell Programming and Scripting

Parsing and filtering multiline text into comma separated line

I have a log file that contains several reports with following format. <Start of delimiter> Report1 header Report1 header continue Report1 header continue Record1 header Record1 header continue Record1 header continue field1 field2 field3 field4 ------... (1 Reply)
Discussion started by: yoda9691
1 Replies

8. Shell Programming and Scripting

displaying a column in horizontal line separated by ', '

cat my.log blah blah blah < 1 djfh jsdfhk jksdfh < 2 dshkfl opeir pqowi < 4 khasd wouipeui say i am perfroming some action similar to below... cat my.log | egrep "<" | awk -F' ' '{print $2}' | grep -v "" it gives output as below 1 2 4 is there anyway to modify above same... (4 Replies)
Discussion started by: vivek d r
4 Replies

9. Shell Programming and Scripting

printing sequence of line no. with comma separated

Kindly i want to concatenate every 12 lines ina file, using a comma separator between fields (each line)? can anyone help please? thanks a lot in advance. (5 Replies)
Discussion started by: m_wassal
5 Replies
Login or Register to Ask a Question