LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-03-2007, 06:49 AM   #1
venki
Member
 
Registered: Sep 2006
Location: India
Distribution: suse10.2
Posts: 128

Rep: Reputation: 15
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
 
Old 07-03-2007, 07:17 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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'
 
Old 07-03-2007, 09:39 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Code:
awk '{gsub(/,+/,",\n")}{print}' file
 
Old 07-04-2007, 02:25 AM   #4
venki
Member
 
Registered: Sep 2006
Location: India
Distribution: suse10.2
Posts: 128

Original Poster
Rep: Reputation: 15
Thks pixellany and ghostdog74 , it is working perfectly
 
Old 07-04-2007, 04:40 AM   #5
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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
should suffice. Simple, no?
 
Old 07-04-2007, 09:22 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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:
tr -s "," "\n" your_horiz_file
Doesn't that put two linefeeds whereever there is the double comma?
 
Old 07-04-2007, 09:48 AM   #7
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
@pixellany: no it doesn't. The -s option squashes duplicates, triples, quadruples, etc. See "man tr".
 
Old 07-04-2007, 10:24 AM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Quote:
Originally Posted by timmeke
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
should suffice. Simple, no?
for OP's case, it doesn't matter. sed/awk/tr whatever. They did the job.
by the way, the tr solution should be
Code:
tr -s "," "\n" < file
also noticed that OP's sample output included the "," at the end, ie it is not tr'ed to "\n".
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Horizontal Lines in Photos on HP 722c w/ CUPS rignes Linux - Hardware 0 10-11-2004 05:37 PM
Faint horizontal rolling lines sleepindawg Mandriva 2 07-05-2004 12:51 AM
horizontal lines on screen? svar Linux - General 8 07-12-2003 10:53 AM
Roving horizontal lines thomask Linux - Hardware 0 07-11-2003 03:41 AM
Changing Verical/Horizontal Scan rate riddley Linux - Software 3 04-16-2003 02:18 PM


All times are GMT -5. The time now is 01:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration