I am trying to do in-place editing of each line that begins with the letter D, keeping the last 3 characters appended to the first 15 characters. I found separate sed commands to do the separate functions but cannot figure out how to combine them into a single command line:
# To remove everything except the 1st n characters in every line:
Code:
sed -r 's/(.{15}).*/\1/' file
# To remove everything except the last n characters in every line:
Code:
sed -r 's/.*(.{3})/\1/' file
Example -- I start with this inside "file":
Code:
D some text end
Line that wont be edited because it does not begin with D
D other text end
Other line that wont be edited because it does not begin with D
D similar text end
I want to end up with this inside "file":
Code:
D some text end
Line that wont be edited because it does not begin with D
D other text end
Other line that wont be edited because it does not begin with D
D similar text end
I'm thinking it should be possible to combine the two sed commands but I have not been able to figure out how. Any SED Gurus out there to shed some light?
Thanks!!!