Results 1 to 7 of 7
I'm creating a BASH script where mysql is involve. I can query data to the shell using "mysql -e" commands. I have to query my mysql to get data. The ...
- 06-01-2009 #1Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
input new line for every match input
I'm creating a BASH script where mysql is involve. I can query data to the shell using "mysql -e" commands. I have to query my mysql to get data. The data is in the ff format
data1,data2,data3,data4
I need to make commas to be a new line and remove commas.Is there a way I can output it to the ff format:
data1
data2
data3
data4
I don't want to use perl since I'm not expert on it. I just want it to be simple.
- 06-01-2009 #2Just Joined!
- Join Date
- Dec 2006
- Posts
- 85
well im not much of an expert on bash, so here is the messy way:
echo "data1,data2,data3,data4"|sed -e 's/data1,/data1\n/' -e 's/data2,/data2\n/' -e 's/data3,/data3\n/' -e 's/data4,/data4\n/'
that will echo it into that format...im sure someone else here will be able to gie you a prettier way...
- 06-01-2009 #3
Or you can translate commas into newlines?
cat $INFILE | tr "," "\n" | $OUTFILE
- 06-01-2009 #4Just Joined!
- Join Date
- Dec 2006
- Posts
- 85
- 06-01-2009 #5
You'd be surprised how many different tools there are to get basic jobs such as these done. That's part of the beauty of Unix and its history.
Here is a basic run down of common Unix text processing tools:
Text Processing Commands
One of my favorites is 'cut'.
- 06-02-2009 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 06-02-2009 #7


Reply With Quote
