LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need to remove / (slash) and replace ; (semi-colon) with new line (https://www.linuxquestions.org/questions/linux-newbie-8/need-to-remove-slash-and-replace-%3B-semi-colon-with-new-line-879116/)

rakesh.bharad 05-06-2011 12:57 AM

Need to remove / (slash) and replace ; (semi-colon) with new line
 
Hi,
I am new to unix. and I need to have a shell script which does the following,

1. Remove '/' in the file
2. Replace ';' with new line

Input file (sample):

TL/01039;TL/07014;TL/07016;TL/07046;TL/09476;TL/09522

Output file should be:

TL01039
TL07014
TL07016
TL07046
TL09476
TL09522

Can someone help on this?. I would appreciate if steps involved are explained.

Thanks

Rakesh

Nylex 05-06-2011 01:03 AM

You can use tr to change the semi-colons into newline characters. Look at the man page for tr ("man tr") to see how to use it.

To remove the slashes, you can use sed. You might want to look at this tutorial for sed (particularly the "The essential command: s for substitution" section).

Pipes are also useful for this task.

grail 05-06-2011 02:01 AM

You could try a simple awk:
Code:

awk 'gsub("/","")' RS=";" file


All times are GMT -5. The time now is 10:24 PM.