How to remove space in front of a word in a file?

This is a simple script to show how to remove space in a front of a word from a file. You can learn about this simple command for removing the space in front of a word and execute it fr

remove-a-space-in-front-of-a-words-in-a-file
remove-a-space-in-front-of-a-words-in-a-file

om your end. I was trying to do this using various commands and scripts. but I was unsuccessful in doing it. Later, I just used a simple method to remove the space in front of a word in a file. I’m very happy to share the same with you.

Just use this command to remove the space in front.

cat filename |cut -d”:” -f2 |sort | sed -e ‘s/^[ \t]*//’
cat filename – This will show you all the contents in a file name
# cat filename
  arun
 hemanth
     :karthick
madhan
  Dhanasekar
cut -d”:” -f2 – this willremove : if there are any before a word. -f2 is feild 2
sort – sorting the output in a order
sed -e ‘s/^[ \t]*//’
# cat c |cut -d”:” -f2 |sort | sed -e ‘s/^[ \t]*//’
arun
Dhanasekar
hemanth
karthick
madhan
Now it will show you the output. If you want the output added inside a file just use this 
 cat filename |cut -d”:” -f2 |sort | sed -e ‘s/^[ \t]*//’ > filename.txt

Leave a Reply