0

In the table shown below, I want to delete the white spaces before the ID #, ideally using sed.

   ID,DESC,PRIORITY,
   1178896,SKIP BI UPDATE, Low
   1178900,SKIP BI UPDATE, High 
   1178901,SKIP BI UPDATE, High 

The output should look like this:

ID,DESC,PRIORITY,
1178896,SKIP BI UPDATE, Low
1178900,SKIP BI UPDATE, High 
1178901,SKIP BI UPDATE, High
2
3

Assuming you have GNU sed, the following command should remove all leading whitespace:

sed -E 's/^\s+//' file.txt

or, for POSIX-compatible sed variants

sed 's/^[[:space:]]\{1,\}//' file.txt
15
  • AFAIK, \+ is not POSIX. But \{1,\} and * is. You may also want to anchor that second expression.
    – Kusalananda
    Apr 29 '20 at 12:20
  • sed: illegal option -- E
    – impitnin
    Apr 29 '20 at 12:27
  • @terdon and @Kusalananda good point on POSIX sed, that was too quick of a copy-and-paste there.
    – AdminBee
    Apr 29 '20 at 12:28
  • 2
    @impitnin what operating system are you using? What sed is this? But anyway, just use the POSIX option that AdminBee gave in the answer, that should work everywhere.
    – terdon
    Apr 29 '20 at 12:35
  • 2
    @Philippos Won't remove tabs though. I would have used s/^[[:blank:]]*//.
    – Kusalananda
    Apr 29 '20 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.