Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Following on from my previous question:

Remove slashes/parent paths from filenames inside CSS and Javascript content

I arrived at the following command which replaces any filenames in these files with just the basename:

grep -o -h -E '[A-Za-z0-9:./_-]+\.(png|jpg|gif|tif|css)' |\
  sed "s:[a-zA-z0-9]*/::" `find . -name '*.css' -or -name '*.js'` 

How do I save the output of this command back to the source file for each file processed?

share|improve this question

migrated from stackoverflow.com Jul 12 '11 at 18:01

This question came from our site for professional and enthusiast programmers.

1  
The -i option in sed will make the changes to your files. Can you try modifying your bash line to use this? –  Manny Jul 12 '11 at 16:38
    
@Manny - I get sed: 1: "./example.com-saved/example ...": invalid command code . –  keith Jul 12 '11 at 17:08
    
possible duplicate of Why does sed act differently depending on the output file? –  Gilles Jul 12 '11 at 21:27

2 Answers 2

Late answer to an old question, but I think this is the answer the OP was looking for:

SEDCMD="/[A-Za-z0-9:./_-]+\.(png|jpg|gif|tif|css)/ s:[a-zA-z0-9]*/::"
find . -name '*.css' -or -name '*.js' -exec sed -i "$SEDCMD" '{}' ';'
share|improve this answer

Try a loop, like:

find . -name '*.css' -or -name '*.js' | while read filename; do
  : $filename is the original file name
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.