I have a file:
$ cat file
1 Fred
2 Fred3
3 Fred3
4 Fred3
5 Fred3
6 Fred3
7 Fred3
8 Fred3
9 Fred3
10 Fred3
11 Fred3
12 Fred288
I want to delete the leading numbers, the output should be like this:
$ cat file
Fred
Fred3
Fred3
Fred3
Fred3
Fred3
Fred3
Fred3
Fred3
Fred3
Fred3
Fred288
How can I achieve this goal using sed?
With sed:
sed 's/^[0-9]\+ //' file
Fred
Fred3
Fred3
Fred3
Fred3
Fred3
Fred3
Fred3
Fred3
Fred3
Fred3
Fred288
Do sed -i 's/^[0-9]\+ //' file to store the changes back to the file.
I would also recommend using cut for this
cut -d' ' -f2 file
Options:
-d, --delimiter=DELIM use DELIM instead of TAB for field delimiter
-f, --fields=LIST select only these fields; also print any line that contains no delimiter character, unless the -s option is specified
This will print the second word in each line:
awk '{print $2}' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With