Search complicated strings on file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search complicated strings on file
# 1  
Old 05-08-2010
Search complicated strings on file

Can someone help me? I been figuring out how I can search and extract a complicated search string from a file. The whole string is delimited by a period. And the file where I'm searching is composed of differnt string such as that. For example, I have this search string:

Quote:
sim.lim.13_60.colorValidationResponse
and I have a file containing:

Quote:
acm.omg.19_10.figureRetrieveAnswer
mai.lim.13_60.colorValidationResponse
hmo.bimx.10_10.staffInformationFile
sim.nam.13_60.colorValidationResponse
sim.lim.12_80.colorValidationResponse
sim.lim.13_60.colorValidationRequest
sim.lim.14_90.colorValidationResponse
sim.nam.13_60.colorValidationResponse
Now I need four outputs since my search string is divided into four strings delimited by period:

Quote:
1st Output:
mai.lim.13_60.colorValidationResponse

2nd Output:
sim.nam.13_60.colorValidationResponse
sim.nam.13_60.colorValidationResponse

3rd Output:
sim.lim.12_80.colorValidationResponse
sim.lim.14_90.colorValidationResponse

4th Output:
sim.lim.13_60.colorValidationRequest
# 2  
Old 05-08-2010
Your strings are not that complicated!

Code:
/Users/scott/scripts/tmp $ awk '/^(mai|sim)/' file1
mai.lim.13_60.colorValidationResponse
sim.nam.13_60.colorValidationResponse
sim.lim.12_80.colorValidationResponse
sim.lim.13_60.colorValidationRequest
sim.lim.14_90.colorValidationResponse
sim.nam.13_60.colorValidationResponse
/Users/scott/scripts/tmp $ grep -E 'mai|sim' file1     
mai.lim.13_60.colorValidationResponse
sim.nam.13_60.colorValidationResponse
sim.lim.12_80.colorValidationResponse
sim.lim.13_60.colorValidationRequest
sim.lim.14_90.colorValidationResponse
sim.nam.13_60.colorValidationResponse

gets all the strings you need. What you mean by "1st output", "2nd output", etc. could use some explaining Smilie
# 3  
Old 05-08-2010
Assuming you're looking for a match of all unique pairs of fields 1 and 2 with their unique entries of field 4:

Code:
one_two=$(cut -d'.' -f1,2 <file.txt |sort -u )
foe_rrr=$(cut -d'.' -f4   <file.txt |sort -u |tr ' ' '|' )

for i in $one_two ;do print "\nMatch [$i]: " ;grep $i file.txt |egrep "$foe_rrr" ;done

# 4  
Old 05-08-2010
Hi.

Judging from the output, I'm guessing that the search is intended to be an "OR":
Code:
sim.lim.13_60.colorValidationResponse

means
Code:
sim OR lim OR 13_60 OR colorValidationResponse

possibly restricted to the content of the fields in order. If so, then there are a number of methods, if not then choose from the suggestions so far, or explain with more detail ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Search strings from array in second file

I have a file search_strings.txt filled with search strings which have a blank in between and look like this: S. g. Erh. o. J. v. d. Chijs g. Ehr.I would like to search the strings in the second given Textfile.txt and it shall return the column number. Can anybody help with the correct... (3 Replies)
Discussion started by: sdf
3 Replies

3. Shell Programming and Scripting

Extended replacing of nonspecific strings in text files [beware complicated !]

Well, to make another post at this helpful forum :b::D: I recently tried something like this, I want to replace all those numberings/letters that are located between <string>file://localhost/var/mobile/Applications/ and /Documents/</string> numberings =---- replace with: first... (6 Replies)
Discussion started by: pasc
6 Replies

4. Shell Programming and Scripting

Search multiple Strings in a File

Hi I want to search multiple strings in a file . But the search should start with "From" Keyword and end with before "Where" keyword. Please suggest me. Thanks (2 Replies)
Discussion started by: sboss
2 Replies

5. Shell Programming and Scripting

Script Search replace - complicated

I have a text file for which i need a script which does some fancy search and replace. Basically i want to loop through each line, if i find an occurance of certain string format then i want to carry on search on replace another line, once i replaced this line i will contine to search for the... (7 Replies)
Discussion started by: kelseyh
7 Replies

6. Emergency UNIX and Linux Support

Complicated SED search required

Hi All, I'm trying to extract all the description fields from a MIB file which contain multiple instances of the following text: ENTERPRISE compaq VARIABLES { sysName, cpqHoTrapFlags, cpqSsBoxCntlrHwLocation, cpqSsBoxCntlrIndex, cpqSsBoxBusIndex,... (10 Replies)
Discussion started by: badoshi
10 Replies

7. Shell Programming and Scripting

search file between last occurence of 2 strings

I need to extract the last block of /== START OF SQLPLUS ==/ and /== END OF SQLPLUS ==/. The logifle is written to several times in a day using >> to append. I need a solution using grep/sed. logfile looks like this START OF LOGFILE /== START OF SQLPLUS ==/ ERROR /== END OF SQLPLUS... (5 Replies)
Discussion started by: hanton
5 Replies

8. Shell Programming and Scripting

complicated search within file

Hi, I have following problem. I have a file with time stamps and some data describing what happened between time stamps. Something like this: 10:00 meeting with K meeting with L 11:00 lunch 12:00 work with K 13:00 From this file I have to get a file with... (7 Replies)
Discussion started by: mmike
7 Replies

9. Shell Programming and Scripting

How to search multiple strings in a file

Hi All, I want to search all the ksh scripts that has following details. 1. Search for "exit 0" 2. Search for "sqlldr" or sqlplus" 3. In the above files i want to search for all the script that has no "case" in it. Please advice. Thanks, Deep (2 Replies)
Discussion started by: deepakpv
2 Replies

10. Shell Programming and Scripting

Find information from complicated strings

Hi experts, I have the file with these lines: var1=thu_13:12:32,var2=Microsoft,var3=240ms,var4=Mozilla/4.0_(sun;_MSIR_3-4;_windows.;_NET_1.1323.53 var1=thu_13:13:32,var2=Microsoft,var3=213ms,var4=Mozilla/4.0_(sun;_MSIR_3-4;_windows.;_NET_1.1323.53... (9 Replies)
Discussion started by: lalelle
9 Replies
Login or Register to Ask a Question