Search text pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search text pattern
# 1  
Old 05-25-2010
Search text pattern

Hello folks,

I have a text file of apache logs, that have robots.txt text with logs, i want to search all all words that are with "anyword.txt" but i dont want to search robots.txt in file.

Like i have abcd.txt file

Code:
X.X.X.X - - [25/May/2010:11:12:10+0100] "GET /myimage/index.php?page=http://abcd.com/language/id.txt??? HTTP/1.1" 200 17264 "-" "libwww-perl/5.813" "-"


So i want two things from abcd.txt

1. -> IP-Address [X.X.X.X]
2. -> textfile=id.txt [dont want to search robots.txt]

Last edited by Scott; 05-25-2010 at 04:07 PM.. Reason: Code tags, please...
# 2  
Old 05-25-2010
Code:
sed -n "/robots.txt/!{s/.*\([0-9][0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*\/\(.*\.txt\).*/\1 \2/p;}" file

# 3  
Old 05-25-2010
Code:
grep -v "robots\.txt" |
        egrep -o "(^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s)|([^ /]+\.txt)"

# 4  
Old 05-25-2010
Quote:
Originally Posted by anbu23
Code:
sed -n "/robots.txt/!{s/.*\([0-9][0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*\/\(.*\.txt\).*/\1 \2/p;}" file


Not Working below error

Code:
-bash: !{s/.*\: event not found



---------- Post updated at 02:02 PM ---------- Previous update was at 02:00 PM ----------

Quote:
Originally Posted by Corona688
Code:
grep -v "robots\.txt" |
        egrep -o "(^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s)|([^ /]+\.txt)"


It is also searching robots.txt as well. I have total 4 lines of log file, it will search all ips and all txt file including robots.txt and after that it hangup, it will not exit automatically.

Last edited by Scott; 05-25-2010 at 04:07 PM.. Reason: Code tags, please...
# 5  
Old 05-25-2010
Try single quotes
Code:
sed -n '/robots.txt/!{s/.*\([0-9][0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*\/\(.*\.txt\).*/\1 \2/p;}' file

# 6  
Old 05-25-2010
Quote:
Originally Posted by anbu23
Try single quotes
Code:
sed -n '/robots.txt/!{s/.*\([0-9][0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*\/\(.*\.txt\).*/\1 \2/p;}' file

the ip address is this

010.020.232.231 but it is showing -> 0.020.232.231

should i use below one?

Code:
sed -n '/robots.txt/!{s/.*\([0-9][0-9][0-9][0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*\/\(.*\.txt\).*/\1 \2/p;}'

if i want to search *.txt and *.php what change i should do?

Last edited by learnbash; 05-25-2010 at 04:24 PM..
# 7  
Old 05-25-2010
Code:
sed -n '/robots.txt/!{s/\([0-9]\{1,\}\.[0-9]*\.[0-9]*\.[0-9]*\).*\/\(.*\.[tp][hx][tp]\).*/\1 \2/p;}' file

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/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

3. Shell Programming and Scripting

Search and Replace a text if the line contains a pattern

My text file looks like below . . . abcdefghi jklmnop $Bad_ptrq_GTS=rcrd_ip.txt $Bad_abcd_REJ=rcrd_op.txt ghijklm $Bad_abcd_TYHS=rcrd_op.txt abcgd abcdefghi jklmnop $Bad_ptrq_GTS=rcrd_ip.txt (2 Replies)
Discussion started by: machomaddy
2 Replies

4. Shell Programming and Scripting

How to use sed to search a particular pattern in a file backward after a pattern is matched.?

Hi, I have two files file1.txt and file2.txt. Please see the attachments. In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
Discussion started by: saurabh kumar
9 Replies

5. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

6. Shell Programming and Scripting

To Search for a pattern and substring text in a file

I have the following data in a text file. "A",1,"MyTextfile.CSV","200","This is ,line one" "B","EFG",23,"MyTextfile1.csv","5621",562,"This is ,line two" I want to extract the fileNames MyTextfile.CSV and MyTextfile1.csv. The problem is not all the lines are delimited with "," There are... (3 Replies)
Discussion started by: AshTrak
3 Replies

7. Shell Programming and Scripting

bash: need to have egrep to return a text string if the search pattern has NOT been found

Hello all, after spending hours of searching the web I decided to create an account here. This is my first post and I hope one of the experts can help. I need to resolve a grep / sed / xargs / awk problem. My input file is just like this: ----------------------------------... (6 Replies)
Discussion started by: bash4ever
6 Replies

8. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

9. Shell Programming and Scripting

Print a pattern between the xml tags based on a search pattern

Hi all, I am trying to extract the values ( text between the xml tags) based on the Order Number. here is the sample input <?xml version="1.0" encoding="UTF-8"?> <NJCustomer> <Header> <MessageIdentifier>Y504173382</MessageIdentifier> ... (13 Replies)
Discussion started by: oky
13 Replies

10. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies
Login or Register to Ask a Question