CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
...HOW DO YOU DO THIS from the command line???ahhhh

 



Lord Xar
Novice

Feb 6, 2004, 11:39 AM

Post #1 of 2 (2049 views)
...HOW DO YOU DO THIS from the command line???ahhhh Can't Post

I want to open up all files and check the first 10 lines to see if it has a certain entry (timestamp)....if it doesn't - I want to add this:

[% # ID: timestamp %]

so basically, I have to traverse many different directories and open two types of files (.html and .htm) - check them for the test and write to them if they don't have the timestamp...the timestamp would look like this..

[% #Id:

if it doesn't have that...add what I wanted, else leave alone.

I have this code

Using this regular expression from the command line

find . -type f -name "*.html" |xargs perl -i.bak -pe 's~\[% urlserver %]/images/files/ ~[% urlserver %]/images/files/sub/~g' *.html

basically..the above line just checks for a path of file, and if it exists change it to the one given..

can this be modifed to do what i need?


Lord Xar
Novice

Feb 9, 2004, 5:07 PM

Post #2 of 2 (2040 views)
Re: [Lord Xar] ...HOW DO YOU DO THIS from the command line???ahhhh [In reply to] Can't Post

Since I didn't get any replies....things seemed to 'have' to work out on their own....so here is what I came up with and it works:

fgrep -iLr 'ID:' `find -name \*.html` | xargs -n1 perl -pi.bak -e's/^/ID: \n\n/ unless $i++'

basically, if the file does not contain this string: "ID:"..then I ad it to the top of the file.

this recurses from the top of the directory tree and goes down.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives