Friday, March 9, 2012

Remove Blank Spaces iand ^M

If you want to remove blank spaces in file . I just leraned that we can use
1." cat <Input filename> | tr –s ‘ ‘ > <Target file name> "
i also know with SED we can replace a blank space by other character by

2.sed s/ /*/g filename.
sed -i -e "s/[ <tab>]*//g" in.txt
3.tr -d ' ' < filename.txt
# or even faster
tr -ds ' ' < filename.txt

But with this one indeed you can have problem on some Unix systems.

4.So to delete all empty lines from a file called /tmp/data.txt, enter:
$ sed '/^$/d' /tmp/data.txt
To store output to another file use redirection operator:
$ sed '/^$/d' /tmp/data.txt > /tmp/output.txt

NOTE : To remove a file which have spaces in between its name
Another format:rm file\ with\ spaces\ in\ the\ name

Use quotes to surround the file name:rm "file with a space.txt"
Update: use the quotes to enclose the whole path to the file:


Remove empty lines from a file
=====================
1.)sed '/^$/d' myFile > myFile
2.)grep -v "^$" filename > newfilename
3.)sed -i '/^$/d' example_file


Remove ^M
======================
:%s/(ctrl-v)(ctrl-m)//g

No comments:

Post a Comment