sed !!1
hi
i am using sed to make dynamic cnages on the fly in one of my log files. the org log file looks like this: RETR "RETR account.cfm" /root/http/myfiles/account.cfm & i am trying to change this line to: get account.cfm how do i do that ? is it possible using sed or do i need to use awk? waiting ur all responses. |
assuming that account.cfm is always in the 3rd position...
awk '{print "get " $3}' logfilename | sed 's/.$//g' You could probably do it all with sed but awk was a little easier to make it just grab the 3rd field... |
hi blinker ...
hello ..
thnks for replying,,, i tried as u said but it adds the "get" on all the lines of the log file , what i want is "get" should be added only on the line which lloks like this: RETR "RETR hello.cfm" /root/home/test/hello.cfm & i want only such lines which start with a RETR to be changed to: get hello.cfm etc... hope u understand what i mean. thanks & waiting for ur reply |
Sorry had a brain fart... ;)
try this... grep RETR LOGFILENAME | awk '{print "get " $3}' | sed 's/.$//g' Hold on that will just get the RETR lines... thinking give me a sec... ;) Quick question are you only looking for files named .cfm and will the /root/http... always be what you want removed? cause if you are something like: sed 's/RETR..RETR/get/g' FILENAME | sed 's/cfm.*root*/cfm/' Might do the job... |
hi again
it works fine by replacing the line that starts with RETR with get <filename> ...
but theres a problem , rest of the lines of the log file are washed away, but i dont want that. i want the rest of thelines to be the same as they were & only the line that starts with RETR should be changed to get <filename> thnks again |
How about some sample lines? like some lines that are similar that you want left in the log file?
|
my org log file looks like this for ex:
USER "USER test4" PASS "PASS test4" CWD myfiles "CWD myfiles" RETR "RETR welcome.cfm" /root/http/myfiles/welcome.cfm STOR "STOR email.cfm" /root/http/myfiles/email.cfm RETR "RETR hello.cfm" /root/home/test/hello.cfm RNFR "RNFR old.cfm" /root/songs/old.cfm RNTO "RNTO new.cfm" i was also wondering how could I change the STOR & RNFR & RNTO lines in the above log file to : USER "USER test4" PASS "PASS test4" CWD myfiles "CWD myfiles" get welcome.cfm put /root/http/myfiles/email.cfm email.cfm get hello.cfm rename /root/songs/old.cfm new.cfm this is how i want my log file to be changed,ie 1) RETR --> get <filename> 2) STOR --> put /URL/<filename> <filename> 3) RNFR & RNTO ---> rename /URL/<oldfilename> <newfilename> i hope u know what i mean .... so i want the abov |
***sorry posted while you were... *** ignore this... ;)
sed -r 's/RETR..RETR.*.myfiles./get/g' LOGFILE here's one that looks the RETR and the myfiles (WARNING If myfiles is not there this one won't change anything!) here's my junk file for testing: RETR "RETR account.cfm" /root/http/myfiles/account.cfm RETR "RETR account3.cfm" /root/http/myfiles/account.cfm RETR "RETR account2.cfm" /root/http/myfiles/account.cfm RETR "RETR account1.cfm" /root/http/myfiles/account.cfm account1.cfm" /root/http/myfiles/account.cfm account1.cfm" /root/http/myfiles/account.cfm ETR account1.cfm" /root/http/myfiles/account.cfm count1.cfm" /root/http/myfiles/account.cfm test test.cfm test test test test.cfm test test test test test test test.cfm test test test test test test test.cfm and after I run sed -r 's/RETR..RETR.*.myfiles./get/g' LOGFILE getaccount.cfm getaccount.cfm getaccount.cfm getaccount.cfm account1.cfm" /root/http/myfiles/account.cfm account1.cfm" /root/http/myfiles/account.cfm ETR account1.cfm" /root/http/myfiles/account.cfm count1.cfm" /root/http/myfiles/account.cfm test test.cfm test test test test.cfm test test test test test test test.cfm test test test test test test test.cfm |
did u read my prev mail |?
waiting for ur reply? thanks |
sorry went to lunch... ;) little fried rice and some sweet and sour chicken :D:D:D
Think I finally figured out the RETR one... the other 2 should be similar... sed 's/RETR..RETR/get/g' FILENAME | sed 's/get.*cfm./&blinkerfluid/g' | sed 's/.blinkerfluid.*//g' |
The mother of all sed commands!
sed 's/RETR..RETR/get/g' FILENAME | sed 's/get.*cfm./&blinkerfluid/g' | sed 's/.blinkerfluid.*//g' | sed 's/STOR..STOR\(.*\) \(.*\)/get \2 \1/g' |sed 's/RNTO..RNTO\(.*\) \(.*\)/rename \2 \1/g' | sed 's/RNFR..RNFR\(.*\) \(.*\)/rename \2 \1/g'| sed 's/cfm.$/cfm/' k so I learned a few shortcuts with the later commands... ;) I think you can also use some other command like a -e instead of piping but I'll have to look into it more... one item that you may want to think about the RNTO line was originally: RNTO "RNTO new.cfm" and you wanted it changed to rename? Might want to look at that one because there isn't a path after... |
what does the " &blinkerfluid " do ?
|
Quote:
|
i am not specific to only .cfm files it can be anything, say a .txt, .bin or any other file?
|
Oh sure ;)
Give me a minute... |
All times are GMT -5. The time now is 08:33 AM. |