paxie
paxie

Reputation: 197

Removing all spaces from the beginning of lines

      1 147.31.124.135
      1 147.31.9.135
      1 147.32.123.135
      1 147.32.123.136
      1 147.32.124.135
      1 77.236.192.69
      1 86.49.86.108
      1 86.49.86.109

Hello. I have file in this format with many spaces at the beginning of every line and i wold like to remove those spaces from beginning and printed all fields using awk or sed.

RESULT:

1 147.31.124.135
1 147.32.123.135
1 147.32.123.136
1 147.32.124.135
1 77.236.192.69
1 86.49.86.108
1 86.49.86.109

Upvotes: 10

Views: 29280

Answers (5)

Sakibul Kabir Risat
Sakibul Kabir Risat

Reputation: 1

You can even use POSIX character class [:space:] which will handle all whitespace (\t, \r, \n, \v, etc.):

sed 's/^[[:space:]]*//g' file

Upvotes: 0

lulinha
lulinha

Reputation: 21

Use awk command,

bash-3.2$ cat input
      1 147.31.124.135
      1 147.31.9.135
      1 147.32.123.135
      1 147.32.123.136
      1 147.32.124.135
      1 77.236.192.69
      1 86.49.86.108
      1 86.49.86.109
bash-3.2$ awk 'sub(/^ */, "")' input
1 147.31.124.135
1 147.31.9.135
1 147.32.123.135
1 147.32.123.136
1 147.32.124.135
1 77.236.192.69
1 86.49.86.108
1 86.49.86.109

Upvotes: 1

P.P
P.P

Reputation: 121347

You can even use POSIX character class [:space:] which will handle all whitespaces (\t, \r, \n, \v etc):

sed 's/^[[:space:]]*//g' file

Upvotes: 11

Eugene Yarmash
Eugene Yarmash

Reputation: 149736

You can use this sed command to remove leading whitespace (spaces or tabs)

sed 's/^[ \t]*//' file 

Use sed -i to modify the file in-place.

Upvotes: 22

Joseph Quinsey
Joseph Quinsey

Reputation: 9952

The sed command

   sed 's/^ *//'

should work.

Explanation: ^ indicates the start of a line, and * indicates zero or more spaces. These are replaced by nothing.

Upvotes: 5

Related Questions