Exact match and #


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exact match and #
# 1  
Old 06-10-2012
Exact match and #

Hi friends,
i am using the following grep command for exact word match:
Code:
 >echo "sachin#tendulkar" | grep -iw  "sachin"
output: sachin#tendulkar

as we can see in the above example that its throwinng the exact match(which is not the case as the keyword is sachin and string is "sachin#tendulkar". i think it is ignoring the substring before # and taking it as a exact match). is there any other command to find the exact search?
thank you in advance

shell: ksh88
# 2  
Old 06-10-2012
Try -x for whole line match.. # is not a word character and therefore sachin is considered a word...
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 06-10-2012
but that option does not seems to be working in ksh88 Smilie
Code:
> echo "sachin#tendulkar" | grep -x  "sachin"
grep: illegal option -- x
Usage: grep -hblcnsviw pattern file . . .

i dont know what is the problem. is there any other way out?
# 4  
Old 06-10-2012
you should use -o option for the exact pattern matching string

Code:
 > echo "sachin#tendulkar" | grep -o "sachin"

Please try this one.
# 5  
Old 06-10-2012
@neelmani:
Use /usr/xpg4/bin/grep instead of grep
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 06-10-2012
@scrutinizer : thanks its working. Smilie may i know the reason behind writting the full path?
# 7  
Old 06-10-2012
/usr/bin/grep is not the POSIX compliant version on Solaris. POSIX compliant versions of utilities can be found in /usr/xpg4/bin or /usr/xpg6/bin
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Replacing exact match

Hi All, My Input file contains a 1000’s of lines in which I have to replace a a string to the other. Here the problem is, I have the lines in my Input as below. Cable Yes && !Pay TV && !ADS \noUE \Label="Cable Yes && !Pay TV && !ADS" I want to replace exactly the string Cable Yes &&... (37 Replies)
Discussion started by: am24
37 Replies

3. Shell Programming and Scripting

Help match the exact string

I just want to match "binutils1_test" only, and print the match line only lyang001@lyang001-OptiPlex-9010:/tmp$ cat file zbinutils1_test bbinutils1_test binutils1_test w-binutils1_test lyang001@lyang001-OptiPlex-9010:/tmp$ cat file |grep -w 'binutils1_test' ... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

4. Shell Programming and Scripting

Grep exact match

Hello! I have 2 files named tacs.tmp and tacDB.txt tacs.tmp looks like this 0 10235647 102700 106800 107200 1105700 tacDB.txt looks like this 100100,Mitsubishi,G410,Handheld,,0,0,0 100200,Siemens,A53,Handheld,,0,0,0 100300,Sony Ericsson,TBD (AAB-1880030-BV),Handheld,,0,0,0... (2 Replies)
Discussion started by: Cludgie
2 Replies

5. UNIX for Dummies Questions & Answers

Exact match question

Hi guys, I am using Centos 6.3. Actually I posted similar question but I still have some minor problem need be fixed. I have two files, file1:target: gi|57529786|ref|NM_001006513.1| mfe: -31.4 kcal/mol p-value: 0.006985 target: gi|403048743|ref|NM_001271159.1| mfe: -29.6 kcal/mol p-value:... (11 Replies)
Discussion started by: yuejian
11 Replies

6. Shell Programming and Scripting

Exact match using sed

I would like replace all the rows in a file if a row has an exact match to number say 21 in a tab delimited file. I want to delete the row only if it has 21 any of the rows but it should not delecte the row that has 542178 or 563421. I tried this sed '/\<21\>/d' ./inputfile > output.txt ... (7 Replies)
Discussion started by: Kanja
7 Replies

7. Shell Programming and Scripting

exact string match ; search and print match

I am trying to match a pattern exactly in a shell script. I have tried two methods awk '/\<mpath${CURR_MP}\>/{print $1 $2}' multipath perl -ne '/\bmpath${CURR_MP}\b/ and print' /var/tmp/multipath Both these methods require that I use the escape character. I am guessing that is why... (8 Replies)
Discussion started by: bash_in_my_head
8 Replies

8. Shell Programming and Scripting

Exact Word Match

I'm trying to find a exact word match but couldn't do it. ABC ABC_NE Searching for ABC_NE tried grep -w </ABC_NE/> grep "^ABC_NE$" but didn't worked , any awk variants would also help. ---------- Post updated at 08:40 AM ---------- Previous update was at 06:48 AM ---------- I... (2 Replies)
Discussion started by: dinjo_jo
2 Replies

9. Shell Programming and Scripting

How to get exact match sentences?

Hi, I have sentences like this: $sent= Protein modeling studies reveal that the RG-rich region is part of a three to four strand antiparallel beta-sheet, which in other RNA binding protein functions as a platform for nucleic acid interactions. Heterogeneous nuclear ribonucleoparticle... (19 Replies)
Discussion started by: vanitham
19 Replies

10. UNIX for Advanced & Expert Users

Exact Match thru grep ?????

hey..... i do have text where the contents are like as follows, FILE_TYPE_NUM_01=FILE_TYPE=01|FILE_DESC=Periodic|FILE_SCHDL_TYPE=Daily|FILE_SCHDL=|FILE_SCHDL_TIME=9:00am|RESULTS=B FILE_TYPE_NUM_02=FILE_TYPE=02|FILE_DESC=NCTO|FILE_SCHDL_TYPE=Daily|FILE_SCHDL=|FILE_SCHDL_TIME=9:00am|RESULTS=M... (2 Replies)
Discussion started by: manas_ranjan
2 Replies
Login or Register to Ask a Question