I need to change the last column of a file:
dir_/agra_2008_04_07_a 6 scd679 Voice of male
dir_/agra_2008_04_07_a 7 scd680 voice off
dir_/agra_2007_10_01_a 2 scd502 voice over
dir_/agra_2007_10_08_a 2 scd502 voice over
to this other:
dir_/agra_2008_04_07_a 6 scd679 Voice_of_male
dir_/agra_2008_04_07_a 7 scd680 voice_off
dir_/agra_2007_10_01_a 2 scd502 voice_over
dir_/agra_2007_10_08_a 2 scd502 voice_over
Adding underscores to the last column! Anyone? Thank you!
A simple sed
solution:
sed 's/ /_/8g' file
It replaces spaces with underscores, but ignoring the first 7 occrences, hence starting with the 8th to the end ( g
). It works if your output has always the same number of spaces until the last column.
As long as you have double space as field separator you can use this awk
awk -F" " '{gsub(/ /,"_",$NF)}1' OFS=" " file
dir_/agra_2008_04_07_a 6 scd679 Voice_of_male
dir_/agra_2008_04_07_a 7 scd680 voice_off
dir_/agra_2007_10_01_a 2 scd502 voice_over
dir_/agra_2007_10_08_a 2 scd502 voice_over
It replace space on last filed with _
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.