2

I am trying to remove the numbers at the start of the line with the following command:

sed -i 's/^\d*\t//' sea_news_2020_corpus.txt

The line looks as follows:

809940  The sea will be moderate in the Arabian Gulf and slight to moderate in Oman.

Why does this not work? Tried it for a long time

ilkkachu
  • 138,973

1 Answers1

6

Sed does not understand \d for a number. For that use [0-9] or more correctly [[:digit:]]

 sed -i 's/^[0-9]*\t//' yourfile

EDIT:

  • \t is not universally understood by sed. POSIX does not mandate it. So use a shell variable for that or slip in an escaped TAB using a construct inspired from ksh $'\t'
  • in place edits -i on Mac needs an argument following it , though GNU is forgiving here. Note that -i is not mandated by Posix.
sed -i"" -e $'s/^[[:digit:]]*\t//' input_file

TAB=$(echo x | tr x '\011')
# or $(printf '\t')
sed -i"" -e "s/^[[:digit:]]*$TAB//" input _file
guest_7
  • 5,728
  • 1
  • 7
  • 13
  • 1
    You are very right on all three. I thought that the OP is using GNU sed because of the lone -i so => \t will be understood. But I shall add your observations to make the post future complete. Thanks. – guest_7 Dec 13 '21 at 00:48