Multiple Grep command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple Grep command
# 1  
Old 10-25-2014
Multiple Grep command

Hi,

I have an url.txt I need check them and grep some data.

url.txt
Code:
domain.com
domain2.com
domain3.com
.....

All sites urls have in source this patterns:
Code:
"web=pattern1"
"net++pattern2"
"office**pattern3"

I need this output:

Code:
domain.com: pattern1,pattern2,pattern3
domain2.com: pattern1,pattern2,pattern3

If there is no a pattern:

Code:
domain.com: pattern1,zero,pattern3
domain2.com: pattern1,pattern2,zero


Last edited by tara123; 10-25-2014 at 09:28 PM..
# 2  
Old 10-25-2014
What have you tried so far?
# 3  
Old 10-25-2014
I can not for multiple url and multiple pattern. Thanks.

my code:

Code:
wget -q www.domain.com -O - | grep -o -E -m 1 '"web=([^"#]+)"' | cut -d'=' -f2


Last edited by tara123; 10-25-2014 at 09:26 PM..
# 4  
Old 10-26-2014
Well, give this a try:
Code:
wget -i url.txt -O - |
awk     '/<(link rel=\"canonical\"|base) href/  {if (L++) {for (i=1; i<=3; i++)
                                                                {printf "%s%s", DL, P[i]?P[i]:"zero"; DL=","}
                                                                 printf "\n"
                                                          }
                                                 delete P; DL=""
                                                 gsub (/href="http:\/\/|\/"\/*>/, ""); printf "%s: ", $NF
                                                } 
         match ($0, /"web=[^"]*"/)              {P[1]=substr($0,6,RLENGTH-6)}
         match ($0, /"net++[^"]*"/)             {P[2]=substr($0,7,RLENGTH-7)}
         match ($0, /"office\*\*[^"]*"/)        {P[3]=substr($0,10,RLENGTH-10)}
         END                                    {for (i=1; i<=3; i++)
                                                        {printf "%s%s", DL, P[i]?P[i]:"zero"; DL=","}
                                                 printf "\n"}
        '

and report back. Finding the domain from an html file might be trickier than assumed in above.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep command on multiple line

Hi All, I have some xml files and I need to find out all xml where one specific type of pattern is available.. Pattern 1 ========== <MAP TIMEOUT="" MODE="STANDALONE"> <COMMENT>without Any Mapping</COMMENT> </MAP> Pattern 2 ========== <MAP TIMEOUT="" MODE="STANDALONE"> ... (4 Replies)
Discussion started by: Baharul
4 Replies

2. Linux

How to search multiple word using grep command?

How to search multiple word using grep command for example i want to reserch ANJ001 AA Using ridiculous font, size, and color changes instead of normal space separated text and CODE tags obfuscates what you are trying to do and makes it difficult for volunteers who may want to help you solve... (1 Reply)
Discussion started by: na.dharma
1 Replies

3. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

4. UNIX for Dummies Questions & Answers

Grep - Searching for multiple items using one command

I am performing a regular check on UNIX servers which involves logging onto UNIX servers and using the grep command to check if a GID exists in the /etc/group directory e.g. grep 12345 /etc/group I have five to check on each server, is there anyway I can incorporate them into one command and... (2 Replies)
Discussion started by: @MeDaveT
2 Replies

5. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

6. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

7. Shell Programming and Scripting

Grep command with multiple pattern

Hi, I want to search multiple patterns in a variable. DB_ERR=`echo "$DB_TRANS" | grep "SP2-" | grep "ORA-"` echo $DB_ERR But I am not getting anything in DB_ERR. I want to print each line on seperate line. Could you please help me out in this. Thanks in advance. (14 Replies)
Discussion started by: Poonamol
14 Replies

8. Shell Programming and Scripting

Help with egrep or grep command to meet multiple criteria

Hello, I"m a newbie :). I hope I can learn from the scripting expert. I'm trying to use egrep and grep commands to get the total count by meeting both criteria. So far, I haven't been able to do it. if robot = TLD and barcode = AA, then final count should be 2 if robot = TLD and... (9 Replies)
Discussion started by: MinBee
9 Replies

9. Shell Programming and Scripting

Count occurance of multiple strings using grep command

How to grep multiple string occurance in input file using single grep command? I have below input file with many IDP, RRBE messages. Out put should have count of each messages. I have used below command but it is not working grep -cH "(sent IDP Request)(Recv RRBCSM)" *.txt ... (5 Replies)
Discussion started by: sushmab82
5 Replies

10. Shell Programming and Scripting

print multiple lines using the grep command.

Hi All, Please find my piece of code below. I am trying to grep the word SUCCESS from $LOGFILE and storing in the grepvar variable. And i am placing that variable in a file. Now if i open the file, i can see the four lines but not in seperate four line s but in a paragraph. If am mailing that log... (8 Replies)
Discussion started by: intiraju
8 Replies
Login or Register to Ask a Question