Operating System - HP-UX
1827462 Members
4086 Online
109965 Solutions
New Discussion

Re: Remove all first spaces in a text file

 
SOLVED
Go to solution
Arjen Verhulst
Occasional Advisor

Remove all first spaces in a text file

Hello all,

The output from my scripts generates a textfile. I want delete only the first space characters from the lines in that output file.

Can someone help me?

Thanks,

Arjen
6 REPLIES 6
Stephen Keane
Honored Contributor

Re: Remove all first spaces in a text file

cat your_file | sed -e "s/^[ \t]*//" > new_file

Pete Randall
Outstanding Contributor
Solution

Re: Remove all first spaces in a text file

Arjen,

From Handy One-Liners For Sed (attached):

# delete leading whitespace (spaces, tabs) from front of each line
# aligns all text flush left
sed 's/^[ \t]*//' # '\t'=tab (see note at end of file)


Pete

Pete
Arjen Verhulst
Occasional Advisor

Re: Remove all first spaces in a text file

It's working !!

Thanks for the reply
Suraj Singh_1
Trusted Contributor

Re: Remove all first spaces in a text file

ANother method from within "vi" editor:

try following command (without "):
:%s/ //g

Regards,
Suraj
What we cannot speak about we must pass over in silence.
Dani Seely
Valued Contributor

Re: Remove all first spaces in a text file

Arjen,
Suraj has a good idea, only not quite correct. Within vi, to remove all leading spaces from the file you will want to do the following:
:1,$s/^ //g

Have a great day!
Together We Stand!
Suraj Singh_1
Trusted Contributor

Re: Remove all first spaces in a text file

Hi Dani,

You may try '%s' in place of '1,$s' (of course without ').

Both these syntax are same.

Regards
What we cannot speak about we must pass over in silence.