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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
> 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 ../
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@martin_sea - try just for fun in "testgrep":
g,hi,h
; -)
g,hi,h
; -)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks all for your solutions.
this implies pattern just started with FILL and ends with FILL.