LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 12-24-2009, 05:06 PM   #1
Clutch2
LQ Newbie
 
Registered: Feb 2008
Location: Northern Michigan
Distribution: Debian on Raspberry Pi's
Posts: 14

Rep: Reputation: 0
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
 
Old 12-24-2009, 06:34 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
try not using -i
 
Old 12-24-2009, 07:27 PM   #3
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
Quote:
Originally Posted by Clutch2 View Post
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
 
Old 12-24-2009, 07:34 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
you might want to disable "smilies" when you post. btw, no need to use egrep.
 
Old 12-24-2009, 07:57 PM   #5
Clutch2
LQ Newbie
 
Registered: Feb 2008
Location: Northern Michigan
Distribution: Debian on Raspberry Pi's
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ghostdog74 View Post
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.
 
Old 12-26-2009, 08:04 AM   #6
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
Quote:
Originally Posted by ghostdog74 View Post
btw, no need to use egrep.
there is if you prefer grep to behave as god intended, i.e. the -E behavior.
 
Old 12-26-2009, 08:43 AM   #7
Clutch2
LQ Newbie
 
Registered: Feb 2008
Location: Northern Michigan
Distribution: Debian on Raspberry Pi's
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 12-26-2009, 08:45 AM   #8
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
Quote:
Originally Posted by Clutch2 View Post
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!
 
  


Reply

Tags
files, replace, search, sed, timestamp



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed to change character in text file only once. pobrika Programming 7 09-09-2009 07:43 AM
Using SED to change a file incomingid Linux - Newbie 4 04-17-2009 12:47 PM
Using sed to change everything apart from one string deathalele Programming 2 03-22-2009 12:55 PM
sed to change some values in a file permanently tanveer Linux - General 2 03-23-2008 01:17 PM
Sed - change some thing but not all mijohnst Linux - Newbie 5 09-01-2007 04:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration