need help with finding a word in file's contents


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help with finding a word in file's contents
# 1  
Old 10-01-2008
need help with finding a word in file's contents

Hi,
I need to check if a particular name is already in the file or not and i am using following code for this...

match=$(grep -n -e "$output1" outputfiles.txt )

where output1 is the variable name having names in it and outputfiles.txt is the file name ..and i am using ksh
can anybosy help me with this...
Thanks
# 2  
Old 10-01-2008
And how is this not working? What is the error message? If no error, what results are you getting? Give sample input and expected output. Have you checked the value of $output1 to make sure it has what you are looking for?
# 3  
Old 10-01-2008
Hi, this code is working but it is adding some number as prefix with names. here is the result when i tried to echo $match and $output1
match is 3:'orgn_unt_ip_interface'-08_10_01
file is 'orgn_unt_ip_interface'-08_10_01
so in here output1 is 'orgn_unt_ip_interface'-08_10_01

but match is
3:'orgn_unt_ip_interface'-08_10_01

it is adding 3: with this name,
similarly with other names but with different numbers like
match is 9:'indv_depnd_ip_interface'-08_10_01
file is 'indv_depnd_ip_interface'-08_10_01


and also i need that if there is match in the file it should display only one name but it is showing number of same names but with different digits. it is because that name appears more than once in the file.

match is 11:'segm_memb_interface'-08_10_01
16:'segm_memb_interface'-08_10_01
file is 'segm_memb_interface'-08_10_01
# 4  
Old 10-01-2008
or is there any way if i can suppress digits and colon and only get names
# 5  
Old 10-01-2008
and also one thing more, i just cat outputfiles.txt and found that basically those digits represent corresponding position for the names. here is list of names in outputfiles.txt
hykki
'segm_interface'-08_10_01
'orgn_unt_ip_interface'-08_10_01
'orgn_unt_ip_interface'-08_10_01
'com_cust_cntc_interface'-08_10_01
'cust_aset_liab_ip_interface'-08_10_01
'cust_cont_pref_interface'-08_10_01
'cust_ip_interface'-08_10_01
'indv_depnd_ip_interface'-08_10_01
'indv_occup_ip_interface'-08_10_01
'segm_memb_interface'-08_10_01
'orgn_unt_ip_interface'-08_10_01
'indv_occup_ip_interface'-08_10_01
'cust_aset_liab_ip_interface'-08_10_01
'cust_ip_interface'-08_10_01
'segm_memb_interface'-08_10_01
'segm_interface'-08_10_01
'employee_interface'-08_10_01
'segm_memb_interface'-08_10_01
'indv_depnd_ip_interface'-08_10_01
# 6  
Old 10-01-2008
Quote:
Originally Posted by manmeet
or is there any way if i can suppress digits and colon and only get names
Yes, don't use "-n". Do a man on grep.
# 7  
Old 10-01-2008
Thanks i'll look at it
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding a word through substring in a file

I have a text file that has some data like: PADHOGOA1 IOP055_VINREG5_1 ( .IO(VINREG5_1), .MONI(), .MON_D(px_IOP055_VINREG5_1_MON_D), .R0T(px_IOP054_VINREG5_0_R0T), .IO1() ); PADV30MA0 IOP056_VOUT3_IN ( .IO(VOUT3_IN), .V30M(px_IOP056_VOUT3_IN_V30M)); PADV30MA0 IOP057_VOUT3_OUT (... (2 Replies)
Discussion started by: utkarshkhanna44
2 Replies

2. Shell Programming and Scripting

Finding pattern in a text file and returning a part of the word

Dear All, assume that we have a text file or a folder of files, I want to find this pattern followers*.csv in the text file , and get * as the output. There are different matches and * means every character. Thank you in advance. Best, David (1 Reply)
Discussion started by: davidfreed
1 Replies

3. Shell Programming and Scripting

finding common numbers (contents) across 2 or 3 files

I have 3 files which are tab delimited and have numbers in it. file 1 1 2 3 4 5 6 7 File 2 3 5 7 8 File 3 1 (4 Replies)
Discussion started by: Lucky Ali
4 Replies

4. Shell Programming and Scripting

copy contents of unix file to Word document

Hello, I have a unix file about 3000lines which i want to copy from and paste it into a Word document. If i cat the file and try to scroll through it then not everything is captured so i am getting and incomplete paste. Any help is really appreciated. jak (2 Replies)
Discussion started by: jakSun8
2 Replies

5. Shell Programming and Scripting

Remove specific word from data contents problem asking

Hi, Below is my input file: >tempZ_1 SAFSDAFDSG GGERRTTZZZ ZASRARARET WETPOASDAZ ZZZASASFAS >temp_9 ASAEGPIOEO EIOPIZZZAS FDFGZZZARA ESEAZZZAAS . . Desired output file: (9 Replies)
Discussion started by: patrick87
9 Replies

6. Shell Programming and Scripting

Manipulating word based off of contents

Hello everyone, my first post here, please feel free to inform me if my question can be better formatted so my future posts may be more clear. I have a large text file which I need parsed in one specific way, I have done the rest of the processing, I am simply lacking the last aspect of such. ... (8 Replies)
Discussion started by: ryanfx
8 Replies

7. Shell Programming and Scripting

Finding a word in a file

Hi frndz, i have a flat file like, xxx yyy zzz sss aaa bbb yyy xxx rrr sss ttt yyy ddd zzzz cccc.. look, in this file i want to fetch the substring from one yyy to another one and need to print it then from next values between yyy's.. can you please give me some inputs on this.. ... (10 Replies)
Discussion started by: smr_rashmy
10 Replies

8. Shell Programming and Scripting

Using first word and print their contents using awk

suppose u hava a file G1354R tGGC-CGC D1361N cGAC-AAC I1424T ATC-ACC R768W gCGG-TGG Q1382R CAG-CGG Q178E gCAG-GAG Y181C TAC-TGC .........cont. So the question is By searching for first word i.e.character say R output shud be R768W gCGG-TGG R182P CGG-CCG R189W ... (6 Replies)
Discussion started by: cdfd123
6 Replies

9. Shell Programming and Scripting

Finding word in file then print the preceding....

Hi, I am looking for a way to find a particular word in a file then print a line that precedes this line, as well as this line. Sometimes in a log file there is only one word per line and I need to print one of the lines leading up to the single worded line. Example - I can grep for ouch... (5 Replies)
Discussion started by: g_jumpin
5 Replies
Login or Register to Ask a Question