Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text File manipulation

Status
Not open for further replies.

scottpeter

Programmer
Sep 23, 2003
28
US
I have a file in the following format.

col1_row1, col2_row_1, col3_row_1, col4_row_1, col5_row_1, col6_row_1, col7_row_1, col8_row_1
col1_row2, col2_row_2, col3_row_2, col4_row_2, col5_row_2, col6_row_2, col7_row_2, col8_row_2
col1_row3, col2_row_3, col3_row_3, col4_row_3, col5_row_3, col6_row_3, col7_row_3, col8_row_3
col1_row4, col2_row_4, col3_row_4, col4_row_4, col5_row_4, col6_row_4, col7_row_4, col8_row_4
col1_row5, col2_row_5, col3_row_5, col4_row_5, col5_row_5, col6_row_5, col7_row_5, col8_row_5
col1_row6, col2_row_6, col3_row_6, col4_row_6, col5_row_6, col6_row_6, col7_row_6, col8_row_6


How can I change it to the following format?

col1_row1
col2_row_1
col3_row_1
col4_row_1
col5_row_1
col6_row_1
col7_row_1
col8_row_1
col_row2
col2_row_2
col3_row_2
col4_row_2
col5_row_2
col6_row_2
col7_row_2
col8_row_2
col_row3
col2_row_3
col3_row_3
col4_row_3
col5_row_3
col6_row_3
col7_row_3
col8_row_3
...

Thanks,
Scott
 
One way:
awk -F'[, ]+' '{for(i=1;i<=NF;++i)print $i}' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

How about:
Code:
tr ',' "\n" </path/to/input |tr -d ' ' >output
[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
A safer way if tr is used:
tr ',' '\n' <</path/to/input | sed 's!^ !!' >output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
He he, yet another UUOC (useless use of cat):
xargs -n1<myfile1|tr -d ','
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top