delete number and special charter from file

58 views Asked by At

I would like to use some command in linux that can delete number from file.

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

result

Lukas Graham - 7 Years
Prince Royce - La Carretera
2

There are 2 answers

0
RomanPerekhrest On

With sed:

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

The output:

Lukas Graham - 7 Years
Prince Royce - La Carretera
10
RavinderSingh13 On

Following awk may also help you on same:

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

Output will be as follows:

Lukas Graham - 7 Years
Prince Royce - La Carretera

Explanation: Adding explanation too here:

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.