I was trying to remove tabs from the file using the below command it works when run on command prompt but doesnt works when operated on a file.
echo " New name" | sed -e 's/[ \t]*//'
I was trying to remove tabs from the file using the below command it works when run on command prompt but doesnt works when operated on a file.
echo " New name" | sed -e 's/[ \t]*//'
It's not tab but whitespace...
echo " New name" | tr -d '[:blank:]'
It will work on the file, but sed, by default, does not alter the file itself. Some versions of sed support the '-i' switch (in-place editing):
sed -i -e 's/[ \t]*//' yourfile
If yours doesn't, you can either create a temporary file:
sed -e 's/[ \t]*//' yourfile > yourtempfile
cp yourtempfile yourfile
or use Perl:
perl -i -pe 's/[ \t]+//' yourfile
None of them works when a file contains tabs , can anyone suggest something.
A simple mod of pludi's perl example works for me:
perl -i -pe 's/[ \t]+//g' yourfile
Of course this removes blanks as well as tabs because of the space character in front of the \.
Just checked (shouldn't code when tired):
perl -i -pe 's/[ \t]+//g' yourfile
If this doesn't work then it's not tabs you have to delete.
For the tabs, the command line as follow works fine...
cat file (with tabs) | tr -d '\t'
Thanks only tr -d '\t' works others dont.