Tuesday, December 30, 2014

bash - Use sed to modify and execute previous command


I've got a bunch of pdf files that are joined with a very long command line sitting in a directory. Some are in English and some are in French, differentiated by _e.pdf and _f.pdf.


Because they're joined in a specific order the command line can't be shortened, but I'd like to modify and re-execute it, simply replacing _e by _f. How can I use sed (or other) for this?


Let's say the command is


pdfjoin file1_e.pdf file2_e.pdf file3_e.pdf

and in history it's command 10.


I've got as far as


echo !10 | sed 's/_e.pdf/_f.pdf/g'

which echoes the command I want to run. But I actually want to run that, not just display the command.


Answer



Have you tried backticks?


`echo !10 | sed 's/_e.pdf/_f.pdf/g'`

Though I can't help feeling that you should be using make.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...