Link to home
Start Free TrialLog in
Avatar of srikanthrad
srikanthrad

asked on

grep exact pattern match.

1) I want to do an exact pattern matching

soemthing fill
type : FILL

something manual fill
type : MANUAL_FILL

if I do grep -B 1 "FILL" should return only the first pair of lines. how can I do that?

grep -B 1 -x "FILL" is not working. Please suggest.

2)  How to change the shell from csh to bash?

> echo $SHELL
/bin/csh
chsh -s /bin/bash
chsh: can only change local entries; use ypchsh instead.
> grep bash /etc/shells
/bin/bash
> bash
bash-3.2$ echo $SHELL
/bin/csh
bash-3.2$ exit
> which bash
/bin/bash

3)     #if [ $# -ne 1 ] then
    #    echo "Usage: cat logfile | sh `basename $0` ORDER_TYPE"
    #    exit 1
    #fi
The above if condition is giving me an error. Why is that? looks valid to me.
ASKER CERTIFIED SOLUTION
Avatar of nognew
nognew
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can use egrep -B 1 "^FILL$"
this implies pattern just started with FILL and ends with FILL.
Avatar of srikanthrad
srikanthrad

ASKER

1) Thanks for that.

2)
> ls -la /bin/csh
lrwxrwxrwx 1 root root 4 Feb 18  2009 /bin/csh -> tcsh*
> ls -la /bin/bash
-rwxr-xr-x 1 root root 801504 Feb  1  2008 /bin/bash*

3)
if [ $# -ne 1 ];then
    echo "Usage: cat logfile | sh `basename $0` ORDER_TYPE"
    exit 1

Even If I put a semicolon, I am getting error. But, when I am using $# != 1then I am getting it right.

> ls -la /usr/local/bin/b*
ls: No match.
> ls -la /usr/local/bin/c*
ls: No match.
> ls -la /usr/local/bin/
total 16
drwxr-xr-x  2 root root 4096 Oct 10  2006 ./
drwxr-xr-x 13 root root 4096 Feb 18  2009 ../
SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTW,

there is no need to change your login shell to run your script under bash!

Just put into the very first line of the script

#!/bin/bash

This determines which shell to use for interpreting the script.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@martin_sea - try just for fun in "testgrep":
g,hi,h
; -)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks all for your solutions.