Reputation: 45
I have a file looking like that
blabla1/blabla2/blabla3.ex
blabla4/blabla5/blabla6.ex
blabla7/blabla8/blabla9.ex
and with a script shell linux, I would like to change it to
blabla3 : blabla1/blabla2/blabla3.ex
blabla6 : blabla4/blabla5/blabla6.ex
blabla9 : blabla7/blabla8/blabla9.ex
I didnt succeed that with a sed command. My problem is copying text existing in a line at the beginning of each line.
Does anybody have a solution? Thanks
Upvotes: 0
Views: 198
Reputation: 290525
awk
loves these things:
$ awk -F[/.] '{print $(NF-1),$0}' OFS=" : " file
blabla3 : blabla1/blabla2/blabla3.ex
blabla6 : blabla4/blabla5/blabla6.ex
blabla9 : blabla7/blabla8/blabla9.ex
-F[/.]
set field separators to /
or .
.print $(NF-1),$0
print the penultimate field and then the full line.OFS=" : "
set output field separator to space + :
+ space.Upvotes: 4