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
# 1  
Old 10-22-2010
Search for an exact string in Man Pages

Is there hopefully a way to search for an exact string in Man Pages? I know if I want to search for anything containing -c I can just do this.
Code:
/-c

How would I search for "-c"? I want only "-c" to show up. So I tried this.
Code:
/"-c"

It took me literally and looked for the quotes also.

Last edited by cokedude; 10-22-2010 at 05:44 PM..
# 2  
Old 10-22-2010
did you try grep ???
# 3  
Old 10-22-2010
You can use ^ for beginning of line, but apparently not $, at least not on my ksh.
Code:
/^-c

You can grep in the shell history, but there are control characters in there, so look at it with "cat -vte" or "od -bc" first.
# 4  
Old 10-22-2010
I forgot to say I'm talking about in the man pages. When you go to the help pages it says something similar to this.

Quote:
SEARCHING

/pattern * Search forward for (N-th) matching line.
?pattern * Search backward for (N-th) matching line.
n * Repeat previous search (for N-th occurrence).
N * Repeat previous search in reverse direction.
ESC-n * Repeat previous search, spanning files.
ESC-N * Repeat previous search, reverse dir. & spanning files.
ESC-u Undo (toggle) search highlighting.
&pattern * Display only matching lines
---------------------------------------------------
Search patterns may be modified by one or more of:
^N or ! Search for NON-matching lines.
^E or * Search multiple files (pass thru END OF FILE).
^F or @ Start search at FIRST file (for /) or last file (for ?).
^K Highlight matches, but don't move (KEEP position).
^R Don't use REGULAR EXPRESSIONS.
---------------------------------------------------------------------------
# 5  
Old 10-22-2010
Man pages are displayed on $PAGER, so you get your choice. The default is more or less. I use pg when i can get it. However, pager regex rules are a bit kinky.

Beyond what the more or less man page says about pattern searching and moving forward and, if you have a file input, backward:

The man pages have teletype print artifacts in them like "_\ba" for underscored "a" and "c\bc" for bold "c" (\b is backspace to overstrike). You can write a sed routine to flush out the .\b or you can use a web man page.
Code:
sed '
        s/\(.\)\^H\1/\1/g
        s/\(.\)\^H\1/\1/g
        s/\(.\)\^H\1/\1/g
        s/\(.\)\^H_/\1/g
        s/_\^H\(.\)/\1/g
        s/.\^H\(.\)/\1/g
 '|sed '
        /^$/{
                :l
                $b
                N
                s/^\n$//
                t l
                }
 '

or in C:

$ cat mysrc/manclean.c

#include <stdio.h>

static void p_putchar( int c )
{
        if ( c != EOF
          && EOF == putchar( c ) )
        {
                if ( ferror( stdout ) )
                {
                        perror( "stdout" );
                        exit( 1 );
                }

                exit( 0 );
        }
}

main()
{
        static int c ;
        static int c2 ;
        static int c3 ;
        static int ct = 0 ;

        do
        {
                switch( c = getchar() )
                {
                case EOF:
                        if ( ferror( stdin ) )
                        {
                                perror( "stdin" );
                        }
                        continue ;

                case '\b':
                        if ( ct < 2 )
                        {
                                ct = 0 ;
                                continue ;
                        }

                        c2 = c3 ;
                        ct = 1 ;
                        continue ;

                case '\n':
                        if ( ct > 1
                          && c3 == '\n'
                          && c2 == '\n' )
                        {
                                ct = 2 ;
                                continue ;
                        }

                        /* intentional fall through */
                default:
                        break ;
                }

                switch( ++ct )
                {
                case 1:
                        c2 = c ;
                        continue ;

                case 2:
                        break ;
                default:
                        p_putchar( c3 );
                        break ;
                }

                c3 = c2 ;
                c2 = c ;

        } while ( c != EOF );

        switch( ct )
        {
        case 0:
                break ;
        case 1:
                p_putchar( c2 );
        default:
                p_putchar( c3 );
                p_putchar( c2 );
                break ;
        }

        exit( 0 );
}


Last edited by DGPickett; 10-22-2010 at 06:02 PM..
# 6  
Old 10-22-2010
you can use \b

when viewing man, type any of these
Code:
/\b-c\b
/\b-c
/-c\b

# 7  
Old 10-24-2010
Quote:
Originally Posted by kurumi
you can use \b

when viewing man, type any of these
Code:
/\b-c\b
/\b-c
/-c\b

What does the \b do? It doesn't seem like it is doing anything.

Someone figured this out for me and it works.
Code:
"/ -c "

(without the quotes but notice the space before and after the -c)

This also does the trick.
Code:
/[^a-z]-c[^a-z]

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