Re: Parsing a text file based on command line argument.



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
.



Relevant Pages

  • Re: Spawning process with environment variables
    ... starting the shell). ... command on the fly. ... a single-line script to a shell for execution. ... execution of shell scripts instead of writing shell script controlling ...
    (comp.unix.programmer)
  • Re: Itanium console:bypass its interpretation of certain control characters
    ... There's an EFI shell command to turn off the use of escape sequences. ... And I _think_ you can make an EFI boot option point at a shell script, ...
    (comp.os.vms)
  • Re: Spawning process with environment variables
    ... jt@xxxxxxxxxxx (Jens Thoms Toerring) writes: ... starting the shell). ... command on the fly. ... He is saying that you need to use C to write a shell script ...
    (comp.unix.programmer)
  • Re: Cobol fo Unix
    ... > To find what your current library path is use the set command and the ... > set | grep LD_LIBRARY_PATH ... That works in every shell I've used. ... recommends, too, but I suspect they'd just confuse Erez.) ...
    (comp.lang.cobol)
  • Re: Parsing a text file based on command line argument.
    ... and what is d way to call another shell script from ds script... ... Don't use both test and grep. ... You call one shell script from another in the same way as you call ... the checktime is passsed as a command line argument. ...
    (comp.unix.programmer)