Results 1 to 5 of 5
I'm a doing a script. There are some part of the script that I need to do but don't know how to do it.
If I have a text which ...
- 08-03-2010 #1Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
it this possible in bash script
I'm a doing a script. There are some part of the script that I need to do but don't know how to do it.
If I have a text which contains:
Could I rearrange it to:foo,fee,fii,fuu
I don't know if sed can do this. There are some function of sed that I just recently discovered but I don't know if it can do the scenario above.foo
fee
fii
fuu
I'm currently checking a tool/command that could help me do this thing just wandering if there's anyone out there that could suggest on how I could accomplish this.
- 08-03-2010 #2
sed can do this, right.
But you can also use tr in order to replace ',' by newline ('\n').Debian GNU/Linux -- You know you want it.
- 08-03-2010 #3Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
This one do the trickCode:sed -i 's/,/\n/g' YOUR-FILE.txt
- 08-03-2010 #4
If string is in a variable try this.
Code:foo=foo,fee,fii,fuu echo $foo | sed 's/,/\n/g'
- 08-03-2010 #5Linux User
- Join Date
- Aug 2006
- Posts
- 458
if you are using some kind of modern shell, eg bash, ksh etc, they already have internal capabilities to string manipulation
Code:$ text="foo,fee,fii,fuu" $ IFS="," $ set -- $text $ echo $1 foo $ echo $2 fee $ for((i=1;i<=${#};i++)) > do > eval echo \$${i} > done foo fee fii fuu


Reply With Quote
