Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
12-24-2009, 05:06 PM
#1
LQ Newbie
Registered: Feb 2008
Location: Northern Michigan
Distribution: F9, Ubuntu and Cygwin on W2k
Posts: 9
Rep:
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
Last edited by Clutch2; 12-24-2009 at 05:09 PM .
Reason: formating and grammar
12-24-2009, 06:34 PM
#2
Senior Member
Registered: Aug 2006
Posts: 2,695
try not using -i
12-24-2009, 07:27 PM
#3
Member
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183
Rep:
Quote:
Originally Posted by
Clutch2
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
12-24-2009, 07:34 PM
#4
Senior Member
Registered: Aug 2006
Posts: 2,695
you might want to disable "smilies" when you post. btw, no need to use egrep.
12-24-2009, 07:57 PM
#5
LQ Newbie
Registered: Feb 2008
Location: Northern Michigan
Distribution: F9, Ubuntu and Cygwin on W2k
Posts: 9
Original Poster
Rep:
Quote:
Originally Posted by
ghostdog74
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.
Last edited by Clutch2; 12-25-2009 at 06:51 AM .
12-26-2009, 08:04 AM
#6
Member
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183
Rep:
Quote:
Originally Posted by
ghostdog74
btw, no need to use egrep.
there is if you prefer grep to behave as god intended, i.e. the -E behavior.
12-26-2009, 08:43 AM
#7
LQ Newbie
Registered: Feb 2008
Location: Northern Michigan
Distribution: F9, Ubuntu and Cygwin on W2k
Posts: 9
Original Poster
Rep:
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
12-26-2009, 08:45 AM
#8
Member
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183
Rep:
Quote:
Originally Posted by
Clutch2
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!
Thread Tools
Search this Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -5. The time now is 11:52 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News