delimit to newline

basirana
basirana used Ask the Experts™
on
How can I convert following delimited txt file to new line file in unix?
Delimited character is ~

Thanks
Current output
A:100 ~ B:T100 ~ C:100
A:200 ~ B:T200 ~ C:200
 
Expected output
A:100 
B:T100 
C:100
A:200 
B:T200 
C:200

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi basirana,

sed will do this for you quite nicely.  :)

  sed 's/\~/\n/g' oldfile > newfile


Good Luck,
Kent
Most Valuable Expert 2013
Top Expert 2013

Commented:
I think at least AIX's 'sed' can't help here.
How about awk?
awk '{gsub(" ~ ","\n"); print}' oldfile > newfile
 wmp
Hi wmp,

True...  Sad, but true... (Missed that in the post.)


Good catch,
Kent
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Most Valuable Expert 2013
Top Expert 2013

Commented:
... and with an arbitrary number of spaces around the tilde -
awk '{gsub("[ ]*~[ ]*","\n"); print}' oldfile > newfile
Same thing with 'sed' - if capable!
wmp
Top Expert 2007

Commented:
tr '~' '\n' <oldfile | sed "s/^ *//" >newfile

Commented:
or how about perl?

perl -pn -e 's/ ~ /\n/g' file

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial