LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   sed saves w/o a change (http://www.linuxquestions.org/questions/linux-general-1/sed-saves-w-o-a-change-777945/)

Clutch2 12-24-2009 05:06 PM

sed saves w/o a change
 
I expected sed to not change the timestamp on a file if there wasn't a match. It changes every file in the search.



Code:

#! /bin/sh
cd /var/spool/news/rec/crafts/metalworking

/usr/bin/find . -type f -mtime -2 -exec /usr/bin/sed -i 's/MyNewsGroups :)/MyNewsGroups/g' '{}' \;

Ideas?

Thanks,

Clutch

ghostdog74 12-24-2009 06:34 PM

try not using -i

GooseYArd 12-24-2009 07:27 PM

Quote:

Originally Posted by Clutch2 (Post 3803871)
I expected sed to not change the timestamp on a file if there wasn't a match. It changes every file in the search.



Code:

#! /bin/sh
cd /var/spool/news/rec/crafts/metalworking

/usr/bin/find . -type f -mtime -2 -exec /usr/bin/sed -i 's/MyNewsGroups :)/MyNewsGroups/g' '{}' \;

Ideas?

Thanks,

Clutch


you might try something like:

for i in `egrep -rf 'MyNewGroups :)' .`; do sed -i s/MyNewsGroups :)/MyNewsGroups/g; done

ghostdog74 12-24-2009 07:34 PM

you might want to disable "smilies" when you post. btw, no need to use egrep.

Clutch2 12-24-2009 07:57 PM

Quote:

Originally Posted by ghostdog74 (Post 3803971)
you might want to disable "smilies" when you post. btw, no need to use egrep.

I fixed the :) using the code directive as soon as I saw it.

Clutch

edit - wasn't directed to me.

GooseYArd 12-26-2009 08:04 AM

Quote:

Originally Posted by ghostdog74 (Post 3803971)
btw, no need to use egrep.

there is if you prefer grep to behave as god intended, i.e. the -E behavior.

Clutch2 12-26-2009 08:43 AM

Dropping the -i wrote it to the screen
I can't remember the issue with the other suggestion but I couldn't get it to work.

This is what I come up with. Runs fast enough to get the job done.

Code:

grep -l "MyNewsGroups :)" * | xargs /usr/bin/sed -i 's/MyNewsGroups :)/MyNewsGroups/g'

Thanks

Clutch

GooseYArd 12-26-2009 08:45 AM

Quote:

Originally Posted by Clutch2 (Post 3805189)
Dropping the -i wrote it to the screen
I can't remember the issue with the other suggestion but I couldn't get it to work.

This is what I come up with. Runs fast enough to get the job done.

Code:

grep -l "MyNewsGroups :)" * | xargs /usr/bin/sed -i 's/MyNewsGroups :)/MyNewsGroups/g'

Thanks

Clutch

I'm all for anything that works! :)


All times are GMT -5. The time now is 12:18 AM.