|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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!!!! |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
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
__________________
. Spiration channels: Free scripts, programming tutorials and articles Dotcut alerts: Online Press cuttings / news alerts Clearprop: UK microlight school, wiltshire Uk dating: UK safe dating with Topdates About Christo . . |
|
#4
|
|||
|
|||
|
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:
|
|
#5
|
||||
|
||||
|
Quote:
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > shell script to remove a particular line across multiple files in a directory ??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|