I am trying to cut out the middle of each line in a file. All the lines are like this:
79.472850 97 SILENCE
and I need to end up with:
79.472850 SILENCE
As each line has the undesired portion starting at character ten and ending at character 14, I was trying to use sed in this way:
sed "s/\(.\{9\}\).\{6\}//"
but I just end up with everything after character 14. The numbers following the tab space change in every file. What can I do to make sed just cut out the tab and two digits?
Thanks for your help.
As per your input and expected output, this can be a way:
$ echo "79.472850 97 SILENCE" | tr -s " " | cut -d" " -f1,3
79.472850 SILENCE
tr -s " "
deletes repeated spaces.cut -d" " -f1,3
prints 1st and 3rd field based on splitting by spaces.With sed
:
$ sed 's#\([^ ]*\)[ ]*\([^ ]*\)[ ]*\([^ ]*\)#\1 \3#g' <<< "79.472850 97 SILENCE"
79.472850 SILENCE
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