从文件中删除号码和特殊章程

时间:2018-02-12 13:11:40

标签: awk sed

我想在linux中使用一些可以从文件中删除数字的命令。

01 - Lukas Graham - 7 Years [OFFICIAL MUSIC VIDEO]
02 - Prince Royce - La Carretera (Official Video)

结果

Lukas Graham - 7 Years
Prince Royce - La Carretera

2 个答案:

答案 0 :(得分:2)

sed

sed -E 's/^[0-9]+ - |[([].+$//g' file

输出:

Lukas Graham - 7 Years
Prince Royce - La Carretera

答案 1 :(得分:1)

关注awk也可以帮助您:

awk '{sub(/[^a-zA-Z]*/,"");sub(/ [[(].*/,"");print}'   Input_file

输出如下:

Lukas Graham - 7 Years
Prince Royce - La Carretera

说明: 此处也添加说明:

awk '{
sub(/[^a-zA-Z]*/,"");  ##Subsituting by using sub keyword of awk everything from starting to till first occurence of any alphabet comes with NULL in current line.
sub(/ [[(].*/,"");     ##Subsituting from space either [ or ( to till last as per OP request with NULL in current line.
print                  ##Printing the current line now.
}
' file                 ##Mentioning the Input_file name here.