Re: Parsing a text file based on command line argument.
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Sat, 2 Sep 2006 17:46:13 -0400
On 2006-09-02, nm wrote:
Hi,
I have wriiten ds code of line..can u chk what d error in ds...
and what is d way to call another shell script from ds script...
I mean aft getting all the lines starting with "#" we need to call
different scripts corresponding to dese...How can it be done????
If you really want help, speak English, don't top post, read the
replies carefully...
Can you reply soon..it's urgent....
...and don't press your luck.
if test $# -eq 0
then chkTime=`date "+%T" | cut -d":" f1,2`
Why are you using cut?
chkTime=`date "+%H:%M"`
else chkTime=$1
fi
fileName=myconfigfile.txt
flag=false
for line in `cat ${filename}`
That reads the file word by word, not line by line.
do
chkline = `echo $line | grep "^CheckTime"`
There is no need for grep. Use a case statement:
case $line in
CheckTime*) ..... ;; ## $line begins with CheckTime
*) ..... ;;
esac
if test -n ${chkline}
Time=`echo $line | cut -d"=" f2`
There is no need for cut; use parameter expansion:
Time=${line#*=}
if test $Time = $chkTime
That will fail if there are spaces or wildcards or characters
special to the shell in the value of either variable. Quote your
variables:
if test "$Time" = "$chkTime"
flag=true
else
flag=false
fi
fi
if test $flag -eq true
You cannot use the -eq comparison on strings; it tests for integer
equality.
if test grep "^#" line
That line contains three errors.
Don't use both test and grep. Where is grep getting its input? Do
you mean "$line".
echo $line
fi
fi
You call one shell script from another in the same way as you call
any other commnd.
endo
nm wrote:
thanks....the following code of lines will grep the check time and
match d time with d command line argument...RIGHT.
but d problem is ...how can we call diff shell script from within ds
script.....?
Chris F.A. Johnson wrote:
On 2006-09-01, nm wrote:
Chris F.A. Johnson wrote:
On 2006-08-31, nm wrote:
Can anyone help me.I m new to shell script can one pls help me with
it..it's urgent.
I want to parse a text file containing following data:
#####################################
CheckName=xyz_ODC
CheckTime=9:54
Machine=abc.def@xxxxxx
#Disk Space
[101.00000]/abc/def/P/data:: Err->80::Warn_>70<80
[102.00000]/abc/def/xyz/logs/:: Err->80::Warn_>70<80
[103.00000]/abc/def/xyz/archive/:: Err->80::Warn_>70<80
#ProcessCheck
[201.00000]/abc/def/xyz/def/solaris6/bin/def_tes
[202.00000]/abc/def/xyz/def/solaris6/bin/def_ps -x B
[203.00000]/abc/def/xyz/def/solaris6/bin/def_ps -f
[204.00000]/abc/def/xyz/def/solaris6/bin/def_pas
[205.00000]/abc/def/xyz/def/solaris6/bin/def_es
[206.00000]/abc/def/xyz/def/solaris6/bin/def_qs
[207.00000]/abc/def/xyz/def/solaris6/bin/def_trd2defdb -x ALL
#Size Check
[301.00000]/abc/def/xyz/data/def_common.products
[302.00000]/abc/def/xyz/data/def_common.accounts
[303.00000]/abc/def/xyz/data/def_ps_positions.init
[304.00000]/abc/def/xyz/data/def_ps_positions_B.init
#NoOfTrades
[401.00000]/abc/def/xyz/def/solaris6/bin/
#Log Message Check
[501.00000]def_tes.out def_ps.out def_es.out
I want to parse the file based on the CheckTime and get the following
lines Disk Space,ProcessCheck,Size Check,NoOfTrades and call the
scripts corresponding to it.
the checktime is passsed as a command line argument.
It is not clear what you want to do. In what way do you want to
parse the file? Do you mean search for specific lines? If so, what
lines. If not, what?
[please do not top post]
Actually i want to parse the file.
Please be more specific. What do you want from the file?
Enter the time through command
line.if the command line option matches with the checktime mentioned in
the variable below
What "variable" is that?
then call the perl scripts corresponding to it..such as DiskSpace
script,Process CheckScript,Size check script. I hope u understood.
At a guess, the first thing you want is to know whether the file
contains "Checktime=$1", where $1 is the command line argument. You
can do that with grep or awk:
if grep '^Checktime=$1' FILENAME
then
: what???
fi
Or:
awk -v ct="$1" '$1 == "Checktime=" ct {
# DO WHAT???
}'
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
.
- Follow-Ups:
- References:
- Re: Parsing a text file based on command line argument.
- From: nm
- Re: Parsing a text file based on command line argument.
- From: Chris F.A. Johnson
- Re: Parsing a text file based on command line argument.
- From: nm
- Re: Parsing a text file based on command line argument.
- From: nm
- Re: Parsing a text file based on command line argument.
- Prev by Date: Re: How to monitor certain resources in Linux
- Next by Date: Re: about stdout redirect programming
- Previous by thread: Re: Parsing a text file based on command line argument.
- Next by thread: Re: Parsing a text file based on command line argument.
- Index(es):
Relevant Pages
|