awk to grep ".do"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to grep ".do"
# 1  
Old 02-12-2014
awk to grep ".do"

awk command to search dot
i have a file with the following contents
Code:
22.152.25.36 - K##### [03/Jul/2013:18:05:00 -0900] "GET /GMAIL/CheckMail.do HTTP/1.1" 200 44948
22.152.25.36 - K##### [03/Jul/2013:18:05:00 -0900] "GET /GMAIL/getdoMail.gif HTTP/1.1" 200 44948

Now i use the following to return only the first line which matches ".do"
Code:
awk -F\" '($2 ~ ".do\"){print $2}' filename.log | awk '{print $2}' | sort | uniq -c | sort -r

But it returns me both the line. i tried giving \.do also but didint work.
Any help is appreciated.

Last edited by Scrutinizer; 02-12-2014 at 08:16 PM.. Reason: code tags
# 2  
Old 02-12-2014
A regex can be used as a pattern by enclosing it in slashes:
Code:
awk '/\.do/' file

OR
Code:
awk -F\" '$2 ~ /\.do/' file

# 3  
Old 02-12-2014
I sometimes prefer [.] over \. Easier to read when it's surrounded by other slashes.
# 4  
Old 02-12-2014
Actually
Code:
awk -F\" '($2 ~ "\.do"){print $2}' filename.log

does work. If your log file's structure is always the same, try also
Code:
awk  '($7 ~ "\.do"){print $7}' filename.log

in lieu of your two awk commands.
# 5  
Old 02-14-2014
Code:
awk '$7 ~ /.do$/ { print }' file


Last edited by Franklin52; 02-14-2014 at 04:57 AM.. Reason: Please use code tags
# 6  
Old 02-14-2014
If I understand correctly what the OP was trying to do, the simple fix would be to change:
Code:
awk -F\" '($2 ~ ".do\"){print $2}' filename.log | awk '{print $2}' | sort | uniq -c | sort -r

to:
Code:
awk -F\" '($2 ~ /\.do/){print $2}' filename.log | awk '{print $2}' | sort | uniq -c | sort -r

A slightly more complex awk script would eliminate the need for the 2nd invocation of awk, the 1st invocation of sort, and the invocation of uniq:
Code:
awk -F\" '
$2 ~ /[.]do/ {
        split($2, f2f, /[ \t]+/)
        c[f2f[2]]++
}
END {   for(i in c) printf("%4d %s\n", c[i], i)
}' filename.log | sort -r

and still produce the same output.
# 7  
Old 03-19-2014
Quote:
Postaed by: suindar1982
awk to grep ".do"
awk command to search dot
i have a file with the following contents

Code:
22.152.25.36 - K##### [03/Jul/2013:18:05:00 -0900] "GET /GMAIL/CheckMail.do HTTP/1.1" 200 4494822.152.25.36 - K##### [03/Jul/2013:18:05:00 -0900] "GET /GMAIL/getdoMail.gif HTTP/1.1" 200 44948

Now i use the following to return only the first line which matches ".do"


Code:
awk -F\" '($2 ~ ".do\"){print $2}' filename.log | awk '{print $2}' | sort | uniq -c | sort -r

But it returns me both the line. i tried giving \.do also but didint work.
Any help is appreciated.

Following solution may help if we need to get only complete line which matches .do in it.

Code:
awk '{match($7,/\..*/); a=substr($7, RSTART, RLENGTH);} (a==".do"){print}'  file_name

Output will be as follows.


Code:
22.152.25.36 - K##### [03/Jul/2013:18:05:00 -0900] "GET /GMAIL/CheckMail.do HTTP/1.1" 200 44948

Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

2. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

5. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

6. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

7. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

8. Shell Programming and Scripting

ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"

Hi, I don't know hot to make this command work: ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" It should return the list of file .txt It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions (13 Replies)
Discussion started by: DNAx86
13 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

10. Shell Programming and Scripting

grep to find content in between curly braces, "{" and "},"

problem String ~~~~~~~~~~~~~~~~~~ icecream= { smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" } aend = {smart vc4 eatr kalu} output needed ~~~~~~~~~~~~~~~~~~ smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" smart vc4... (4 Replies)
Discussion started by: keshav_rk
4 Replies
Login or Register to Ask a Question