Help with grep (reWriting it in another way.) - Shell Scripting

This is a discussion on Help with grep (reWriting it in another way.) - Shell Scripting ; Hello everyone,I need some help over here with grep i have this grep -n hello filename grep -v hello filename grep -y hello filename grep -i hello filename grep -w hello filename grep -f file hello filename and i did ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Help with grep (reWriting it in another way.)

  1. Help with grep (reWriting it in another way.)

    Hello everyone,I need some help over here with grep

    i have this

    grep -n hello filename
    grep -v hello filename
    grep -y hello filename
    grep -i hello filename
    grep -w hello filename
    grep -f file hello filename


    and i did to execute these commands with a different way. For instance instead of using grep use sed

    for instance i know the answer for the first one.
    grep -n hello filename
    sed -nr '/hello/p' filename

    and for the second one

    grep -v hello filename
    sed -nr '/hello/!p' filename

    i am not sure fo the rest.

    Thanks for your help!!

  2. Thumbs up Re: Help with grep (reWriting it in another way.)

    Here the alternative ways,

    In grep -y and -i options are the same ,so here for both you can use the same sed expression.

    Code:
                     sed -nr '/[h|H][e|E][l|L][l|L][O|o]/p' filename
    For -w option you can use the following,

    Code:
                      sed -n '/\bhello\b/p' filename
    Here \b represents the word boundary.

    For the -f options I created the simple script to achieve that.
    Code:
                            patterns=`cat patterfile`
                            for i in $patterns
                            do
                            val=`sed -ne "/$i/p" searchfile`
                            echo -e "$val"
                            done
    Thanks.

+ Reply to Thread