Sil*_*ler 2 sed text-processing regular-expression
我正在尝试使用以下命令删除行开头的数字:
sed -i 's/^\d*\t//' sea_news_2020_corpus.txt
Run Code Online (Sandbox Code Playgroud)
该行如下所示:
809940 The sea will be moderate in the Arabian Gulf and slight to moderate in Oman.
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?尝试了很久
Sed 不理解 \d 代表数字。为此,请使用 [0-9] 或更正确地使用 [[:digit:]]
sed -i 's/^[0-9]*\t//' yourfile
Run Code Online (Sandbox Code Playgroud)
编辑:
sed -i"" -e $'s/^[[:digit:]]*\t//' input_file
Run Code Online (Sandbox Code Playgroud)
TAB=$(echo x | tr x '\011')
# or $(printf '\t')
sed -i"" -e "s/^[[:digit:]]*$TAB//" input _file
Run Code Online (Sandbox Code Playgroud)