UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 7th, 2004, 06:56 PM
nsobti nsobti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 9 nsobti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question shell script to remove a particular line across multiple files in a directory ???

Hi,

I have a problem! I want to finad all java files in a directory structure (its a really big directory structure!), and go into the java code and remove the first line in the code if it is something (specifically, %modified....). How do I do this?

I was thinking of using shell scripts? SED?

Please help!!!!

Reply With Quote
  #2  
Old March 8th, 2004, 10:50 AM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 262 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 23 h 28 m 59 sec
Reputation Power: 6
Yes you can use the find utility in conjunction with sed.

Here is an example which you will need to modify for
your particular purposes

Code:
   find /tmp -name "*.java" -exec sed 's/^A /a/g' {};


or you could use a loop

Code:
  for tfile in `find /tmp -name "*.java"  -print`
  do  
      sed 's/^A/a/g' $tfile
  done


Of course with sed you need to save the output to
a temporary file and replace the original file with
the temporary file.

Reply With Quote
  #3  
Old March 8th, 2004, 01:30 PM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,297 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 9 m 17 sec
Reputation Power: 104
Send a message via ICQ to christo Send a message via Yahoo to christo
if it's a oneliner you're after, I rekkon this'll do the job (when run from the top directory (ie root of source tree):

find . -type f -name "*java" | xargs perl -pi -e 's/%modified+//g';

christo

Reply With Quote
  #4  
Old March 8th, 2004, 05:15 PM
nsobti nsobti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 9 nsobti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

Thanks a lot for the help. But when I executed the command it just removed the word from the line. But I want to remove te whole line in which %modified appears.

Thanks

Quote:
Originally Posted by christo
if it's a oneliner you're after, I rekkon this'll do the job (when run from the top directory (ie root of source tree):

find . -type f -name "*java" | xargs perl -pi -e 's/%modified+//g';

christo

Reply With Quote
  #5  
Old March 9th, 2004, 03:05 AM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,297 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 9 m 17 sec
Reputation Power: 104
Send a message via ICQ to christo Send a message via Yahoo to christo
Quote:
Originally Posted by nsobti
Thanks a lot for the help. But when I executed the command it just removed the word from the line.


sounds like you just need to meddle with the expression - (ie the bit inside the first / and the second /. You could try just matching everything with *

find . -type f -name "*java" | xargs perl -pi -e 's/%modified*//g';

totally untested of course

christo

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > shell script to remove a particular line across multiple files in a directory ???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate 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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway