Search for an exact string in a Terminal


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Search for an exact string in a Terminal
# 8  
Old 10-24-2010
i used to use

Code:
man any_ninja_command | less

since less highlight the pattern you search for, which is much more confortable

by the way, if
Code:
/-c

didn't work, did you try
Code:
/\-c

?
# 9  
Old 10-24-2010
\b is backspace, part of bold or underline for teletype printers in nroff/troff, which is the "word processor" for man pages.
This User Gave Thanks to DGPickett For This Post:
# 10  
Old 10-24-2010
I'll sleep a bit less ignorant tonight, tya DGnitPickSmilie
# 11  
Old 10-24-2010
I think in this case it stands for "word boundary" not backspace.
This User Gave Thanks to Scrutinizer For This Post:
# 12  
Old 10-24-2010
Oki dude, thanx !
# 13  
Old 10-25-2010
My bad:

Regex Tutorial - \b Word Boundaries

For me, the pattern '-..c' works, because of the overtyping boldness encoded by nroff/troff in the man page, see man grep example below:
Code:
$ man grep             



 grep(1)                                                             grep(1)




 NAME
      grep, egrep, fgrep - search a file for a pattern

 SYNOPSIS
    Plain call with pattern
      grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file ...]
 .
 .
 .
           -c                  Only a count of matching lines is printed.
 .
 .
 .
 .



===========================================================
$ man grep | cat -v



 g^Hg^Hg^Hgr^Hr^Hr^Hre^He^He^Hep^Hp^Hp^Hp(^H(^H(^H(1^H1^H1^H1)^H)^H)^H)             g^Hg^Hg^Hgr^Hr^Hr^Hre^He^He^Hep^Hp^Hp^Hp(^H(^H(^H(1^H1^H1^H1)^H)^H)^H)




 N^HN^HN^HNA^HA^HA^HAM^HM^HM^HME^HE^HE^HE
      grep, egrep, fgrep - search a file for a pattern

 S^HS^HS^HSY^HY^HY^HYN^HN^HN^HNO^HO^HO^HOP^HP^HP^HPS^HS^HS^HSI^HI^HI^HIS^HS^HS^HS
    P^HP^HP^HPl^Hl^Hl^Hla^Ha^Ha^Hai^Hi^Hi^Hin^Hn^Hn^Hn c^Hc^Hc^Hca^Ha^Ha^Hal^Hl^Hl^Hll^Hl^Hl^Hl w^Hw^Hw^Hwi^Hi^Hi^Hit^Ht^Ht^Hth^Hh^Hh^Hh p^Hp^Hp^Hpa^Ha^Ha^Hat^Ht^Ht^Htt^Ht^Ht^Hte^He^He^Her^Hr^Hr^Hrn^Hn^Hn^Hn
      g^Hg^Hg^Hgr^Hr^Hr^Hre^He^He^Hep^Hp^Hp^Hp [-^H-^H-^H-E^HE^HE^HE|-^H-^H-^H-F^HF^HF^HF] [-^H-^H-^H-c^Hc^Hc^Hc|-^H-^H-^H-l^Hl^Hl^Hl|-^H-^H-^H-q^Hq^Hq^Hq] [-^H-^H-^H-b^Hb^Hb^Hbh^Hh^Hh^Hhi^Hi^Hi^Hin^Hn^Hn^Hns^Hs^Hs^Hsv^Hv^Hv^Hvx^Hx^Hx^Hx] _^Hp_^Ha_^Ht_^Ht_^He_^Hr_^Hn [_^Hf_^Hi_^Hl_^He ...]
 .
 .
 .
           -^H-^H-^H-c^Hc^Hc^Hc                Only a count of matching lines is printed.
 .
 .
 .
 .

# 14  
Old 10-25-2010
But it also works if you just use less on a regular plain text file and use word boundaries.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

2. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

3. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

4. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

5. Shell Programming and Scripting

How to use SED or AWK to search and replace an exact string

I have a file DS1 DDS DS I want to replace only "DS" to "DSmail.blah.com" in a lot of files. I tried sed 's/DS/DSmail.blah.com' but it changes all the lines . thanks in advance (2 Replies)
Discussion started by: gubbu
2 Replies

6. Shell Programming and Scripting

search and replace exact string

Hello Everyone, Im trying to run a search and replace of exact strings and the strings that im using variables that are passed through an array in a while loop. Here is a snip of my code: USEROLD=`cat oldusers` USERNEW=`cat newusers` USEROLDARRAY=( $USEROLD ) USERNEWARRAY=( $USERNEW )... (4 Replies)
Discussion started by: skizim
4 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

Search for exact string

Hi All, I need to search in a csv file as mentioend in the Appendix A for a exact word lets "TEST". But using teh below command iam getting TEST1234, TEST12 and otehr entries as well. the problem is i check this condition to check to add a record to a table by making sure it does not... (16 Replies)
Discussion started by: rahman_riyaz
16 Replies

9. UNIX for Dummies Questions & Answers

grep exact string/ avoid substring search

Hi All, I have 2 programs running by the following names: a_testloop.sh testloop.sh I read these programs names from a file and store each of them into a variable called $program. On the completion of the above programs i should send an email. When i use grep with ps to see if any of... (3 Replies)
Discussion started by: albertashish
3 Replies

10. Shell Programming and Scripting

How do I search a File for a string exact match

Hi, Can you help please. I have the following comand: if ]; then l_valid_string="Y" fi The problem I am trying to solve is that my l_string = ABC and my file contains ABC ABC_EFG I only want back the value ABC exact match. (3 Replies)
Discussion started by: CAGIRL
3 Replies
Login or Register to Ask a Question