10.10. Using sed on the system

We have now gone over the basics of sed, but what you really use sed for in your scripts or on the shell line is changing or deleting text from strings or files. That’s what we will look at next, using what we have learnt in the previous section.

10.10.1. Dealing with control characters

One task for which you’ll use sed a lot will be stripping off control characters from files that have been downloaded from another system.

Here’s a part of a file (dos.txt) that has been transferred. We’ve got to get rid of all the suspect characters so the accounts department can use the file.

							$ pg dos.txt 
12332##DISO##45.12^M 
00332##LPSO##23.11^M 
01299##USPD##34.46^M 
...
						

Here’s what has got to be done:

1.
Replace all the ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.