Splitting horizontal to verical...lines
HI i have a file like this ...
"Inter","Hyd bad","General ",,"http://nal.html", "Inter","HYd bad","ca ",,"http://ca.html", "Inter","Hyd bad","cas ",,"http:cass.html", there are 1000 lines like this . i want to make every horizantal line into vertical line. then the output should be "Inter", "Hyd bad", "General ", "http://nal.html", .... plz help me...give the bash script for the following |
To change the double comma to a single:
sed 's/,,/,/g' to replace all the commas with linefeeds: sed 's/,/\n/g' Pipe these together (after cat filename), and you'll get the "vertical list" with one blank line after each set. To remove the last comma so this does not happen: sed 's/,$//g' |
Code:
awk '{gsub(/,+/,",\n")}{print}' file |
Thks pixellany and ghostdog74 , it is working perfectly
|
sed is for stream editing. awk is overkill too. Just use "tr". It takes care of transliteration, prevent double linefeeds, etc.
Code:
tr -s "," "\n" your_horiz_file |
If you just want to do one task, use the first tool that works. If you want to learn programming, try ALL of the tools
Quote:
|
@pixellany: no it doesn't. The -s option squashes duplicates, triples, quadruples, etc. See "man tr".
|
Quote:
by the way, the tr solution should be Code:
tr -s "," "\n" < file |
All times are GMT -5. The time now is 09:54 AM. |