Searching a string stored in other file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching a string stored in other file
# 1  
Old 03-09-2012
Searching a string stored in other file

I need to design a script which can do the following:

I have two files abc.txt and constant.hmtl
abc.txt contains some 5 string that I need to see if they exist in contants.html.

Constants.hmtl is a very large file around 800 lines.
I want to search all the strings present in file abc.txt, and see if they are present in constant.html

Any help will be appreciated?

Last edited by hemasid; 03-12-2012 at 02:13 PM..
# 2  
Old 03-09-2012
Do you need to check for any of the lines, or all of them?
# 3  
Old 03-12-2012
Need to search all of them.

Quote:
Originally Posted by Corona688
Do you need to check for any of the lines, or all of them?
# 4  
Old 03-12-2012
What is not clear (and so how to design...)
abc.txt contains 5 strings, OK but only? and how? 5 lines?

Searching in second file is just a question of reading line per line until EOF...
But how do you want it to treat the finding of the strings?
One option is to enumerate the presence of the found strings if any...

Last edited by vbe; 03-12-2012 at 02:22 PM.. Reason: typo...
# 5  
Old 03-12-2012
I think we can do it with fgrep:
Code:
pandu#fgrep -f abc.txt constant.html

But works only if you want to search the content in constant.html

Hope it works!

Last edited by Franklin52; 03-12-2012 at 02:15 PM.. Reason: Please use code tags for data and code samples, thank you
# 6  
Old 03-12-2012
Modified my Q hope that clears it more

Quote:
Originally Posted by vbe
What is not clear (and so how to design...)
abc.txt contains 5 strings, OK but only? and how? 5 lines?

Searching in second file is just a question of reading line per line until EOF...
But how do you want it to treat the finding of the strings?
One option is to enumerate the presence of the found strings if any...
---------- Post updated at 12:23 PM ---------- Previous update was at 12:14 PM ----------

What is pandu?? I have never seen this before?



Quote:
Originally Posted by satish51392111
I think we can do it with fgrep:
Code:
pandu#fgrep -f abc.txt constant.html

But works only if you want to search the content in constant.html

Hope it works!

Last edited by vbe; 03-12-2012 at 02:22 PM..
# 7  
Old 03-12-2012
Would it not be easier to give us a abc.txt sample?

Depending what you want the above proposition in post#5 might well do the job...

Should read:
Code:
fgrep -f abc.txt constant.html

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string with lines stored in a file

OS version: RHEL 6.7 Shell : Bash I have a file like below $ cat pattern.txt 'T_PKT_HEADER' 'T_ORD_ITM_LOYX' 'T_ORDERITM_TRMS' 'T_ORDER_ITEM' 'T_ORDER_ITM_PRI' 'T_ORDER_ITEM_OM' 'T_ORDER_ITEM_XA' 'T_ORDER_ATT' 'T_ORDER_ACTNSET' 'T_ORDER_XM' 'T_ORDER_X' 'T_ORDER_TNTX'... (7 Replies)
Discussion started by: kraljic
7 Replies

2. Shell Programming and Scripting

Searching a string in a particular file name

Hello, I have a file name like FIRST_DPF_DAILY_CUST_0826152322.txt i need to extract the string after the third "_" underscore upto timestamp ends i.e CUST_0826152322 can anyone help me with the code Thank you! Regards Srikanth Sagi (3 Replies)
Discussion started by: srikanth_sagi
3 Replies

3. UNIX for Dummies Questions & Answers

Searching for a pattern from filenames stored in a file

Hi, I have got some 10 filenames stored in a file or displayed in the console as a result of some query i made.. Now I need to open each of these files and search for a pattern in these 10 files.. Can someone help me with this? Thanks, Jean (9 Replies)
Discussion started by: jeanjkj
9 Replies

4. Shell Programming and Scripting

Searching for a specific string in a file

Hi I am trying to search for a certain set of patterns within a file, and then perform other commands based on output. testfile contents: password requisite pam_cracklib.so lcredit=-1 ucredit=-1 ocredit=-1 script: D="dcredit=-1" if then echo $D exists else echo $D doesnt... (8 Replies)
Discussion started by: bludhemn
8 Replies

5. Shell Programming and Scripting

searching each file for a string

Hi Guys... I want to search for each file that contains a particular string. e.g find . -print | xargs grep -i string_name Now my issue is the files that I search in are gzipped. Will I be able to find the string, using the above commands, even if the files are gzipped? Please... (2 Replies)
Discussion started by: Phuti
2 Replies

6. Shell Programming and Scripting

Searching a string in a file

Hi, I am new to unix shell scripting. I have a requirement. Could anyone help me writing the script for the same? Here goes the requirement: I have a config file let's say temp.config. Here is the data in the config file temp.config : ------------- name=victor age=42 state=texas... (5 Replies)
Discussion started by: badrimohanty
5 Replies

7. UNIX for Dummies Questions & Answers

searching for a string in a file

I need to search for a specific string in a file and if this string exist I need to replace it with something else. I am not sure how I could do this, using an if statement. (2 Replies)
Discussion started by: ROOZ
2 Replies

8. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

9. Shell Programming and Scripting

Perl: searching for a string in a file...

Hi All, I need to search for a string in a file that I've opened and base a decision on the result. The logic is this: "if the word 'Shared' appears on the first line then do this on the whole file else do this on the whole file " The code I currently have isn't working:... (4 Replies)
Discussion started by: pondlife
4 Replies

10. Shell Programming and Scripting

Complicated string searching in a file

Hi folks, Following a part of opmn.xml file: <process-type id="OC4J_RiGHTv_PLATOR81" module-id="OC4J"> <environment> <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/> <variable id="SHLIB_PATH"... (5 Replies)
Discussion started by: nir_s
5 Replies
Login or Register to Ask a Question