LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to remove characters in text file (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-remove-characters-in-text-file-4175598058/)

Entropy1024 01-23-2017 07:26 AM

Script to remove characters in text file
 
Hello all. I need to write a script that will open a text file and find a list of characters strings such as &37, &55 and remove them.

So if there was a line as follows:
This is &37 a &55 quick example

I want it to rewrite the file so that it now reads:
This is a quick example.

If it was just the two characters I needed to remove then I would just use a find/replace on Nano or similar, however there are about 60 of these special characters and a script would be much faster.

Many thanks for any help.

Regards
Tim

smallpond 01-23-2017 07:58 AM

http://www.grymoire.com/Unix/Sed.html

grail 01-23-2017 08:08 AM

Vim could easily do the same, but sed would the tool of choice at the command line.

pan64 01-23-2017 08:13 AM

additionally sed and vim understand the same command.

Entropy1024 01-23-2017 11:57 AM

Quote:

Originally Posted by smallpond (Post 5659001)

Many thanks for all the replies. I will check out Sed & Vim.

Cheers
Tim

szboardstretcher 01-23-2017 12:06 PM

If they are truly 'special characters' like \n and \r or some HEX or OCTAL or UNICODE characters, then you might save time using 'tr' to transform and replace them.

http://www.linfo.org/tr.html
https://linux.die.net/man/1/tr


All times are GMT -5. The time now is 04:13 PM.