- How to remove the control-M characters from file?
File Ascci contains the text shown in below image. The commands shown in the image gives you the desire the output. If you want to save this output in differant file then redirect the desire output in differant file by using redirection operator i.e. '>'.
Here are some different ways to achive the same result....... - command: 'cat Ascci.txt' shows you the content of the file.
- command: 'cat -v Ascci.txt' shows you all the characters in your file.
- command: 'sed 's/^M//g' Ascci.txt' substitutes / replaces the occurances of ^M with ''.
- command: 'sed 's/\r\n//g' Ascci.txt' -- Actually ^M character forms with Carriage Return and a new Line Feed character means 'CR' & 'LF'. So in unix we can say for Carriage Return '\r' and for Line Feed '\n'. Hence substituting with \r\n also provides us the same result.
- command: ' tr -d '^M' < Ascci.txt' -- here we are deleting ^M character from the output and not actually from the inputfile Ascci.txt
- command: 'perl -p -e 's/^M//g' Ascci.txt' -- here we are running perl one liner. Here -p stand to print the output, -e stands for executes the remaining script. in single quotes we are again substituting ^M with '' globally with in entire file Ascci.txt. This also provides us the same desire result.
Monday, May 9, 2011
Some Essentials
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment