Sponsored Content
Full Discussion: substr problem in KSH
Top Forums Shell Programming and Scripting substr problem in KSH Post 102243 by asinha63 on Thursday 16th of March 2006 12:40:04 PM
Old 03-16-2006
substr problem in KSH

in my script i have a command which will sum a particular value of all the lines in a file not beginning with H or T .
I have given the following commands

-------------------------------------------------------------
RCRD_CTRL_VAL_1_SUM=`awk '/^[^HT]/{ SUM+=substr($0,${TRLR_CTRL_VAL_1[0]},${TRLR_CTREL_VAL_1[1]})}END {printf "%015.2f", SUM}'
$FILE_NAME`

where the array values
TRLR_CTRL_VAL_1[0] =98 and
TRLR_CTRL_VAL_1[1] =10 ( the positions of the amount to be summed )

but this is thrwoing an error :-
Syntax Error The source line is 1.
The error context is
/^[^HT]/{ >>> SUM+=substr($0,${ <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-500 Quitting The source line is 1.

pls tell me the solution .

do i have to intialize the position and length values in BEGIN?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh problem

when declaring a variable e.g. export DAYS what checking / how can i check that the value assigned only contains numeric characters or integers ? (1 Reply)
Discussion started by: jinky
1 Replies

2. Shell Programming and Scripting

ksh case problem

I'm trying to run a ksh script with a case condition to handle parameters. #!/bin/ksh db_start(){ *code } db_shut(){ *code } case "$1" in up) db_start TRNG ;; down) db_shut TRNG ;; *) echo "Usage: $0 { up | down }" (3 Replies)
Discussion started by: digiteck
3 Replies

3. Shell Programming and Scripting

Ksh problem in script

Hi I made a small script which uses ksh. When i run the script then i get the following error However when i run each of the commands on the commandline they get executed and provide the desired output. i cant figure out why the script is not running. Kindly Help Thanks in... (3 Replies)
Discussion started by: PradeepRed
3 Replies

4. UNIX for Dummies Questions & Answers

strange problem for substr

i have following in block if then echo "Exclusion criteria" else echo "Not exclusion criteria" fi now above block runs fine if value of variable line_by_line is "00000000dfahfahfahfahsfhasfhafhahfahfahf" but same block gives error if value is "0000000000202000501000069BAG ICE ... (1 Reply)
Discussion started by: mahabunta
1 Replies

5. Shell Programming and Scripting

Please help problem in KSH

Hi All, I have got a problem. I have written a Shell script which cuts some information from the file a and puts it in file b. But i get this error when i execute the shell script. This is what i have written in the script. #! /usr/bin cd /test ls $2 > a cut -f 1 -d '.' a > b When i... (2 Replies)
Discussion started by: srikanthshastry
2 Replies

6. Shell Programming and Scripting

Ksh problem

I am having a problem with this command working, can anyond help? $ export Path=/user/bin user/local/bin /user/ucb/bin (2 Replies)
Discussion started by: vthokiefan
2 Replies

7. Shell Programming and Scripting

sed problem in ksh

Hi, I have the following issue while replacing text in a file usind sed $ cat file $ One,ABCD\XYZ,Server one i want to replace ABCD\XYZ with another text SERVER. with ABCD\XYZ stored in a variable. #!/bin/ksh VAR=ABCD\XYZ echo $VAR cat file | sed 's/'"$VAR"'/SERVER/' ... (14 Replies)
Discussion started by: sudheer1984
14 Replies

8. Shell Programming and Scripting

problem in assigning substr to a variable inside awk

Hi All, I have a fixed-width datafile from which i need to extract value/string starting from some position to the specified length in each of the lines. awk '{print substr($0,x,y)}' datafile --- is working fine but awk 'BEGIN{a=0}{a=substr($0,x,y);print $a}' datafile ---is giving... (3 Replies)
Discussion started by: loggedin.ksh
3 Replies

9. Shell Programming and Scripting

Execution problem with ksh

Dear All, I have a script as follows: 1 #! /bin/ksh 2 # 28 varDate=`date +%d%h%y` 29 export spool_file=/app/my_user/work/TH_Status_${varDate}_Check.txt 30 31 ######################### 32 # Unix Code Starts here # 33 ######################### ... (3 Replies)
Discussion started by: saps19
3 Replies

10. Shell Programming and Scripting

ksh and mail problem

Script A: #!/bin/ksh /usr/bin/mail -s "case 4" g@f.com <testF5Email.inp Script B: #!/bin/ksh qq="-s \"case 4\" cstsang@hko.hksarg" /usr/bin/mail $qq<testEmail.inp Script A working properly where Script B cannot. The error message as the following: There is a missing '"' character... (3 Replies)
Discussion started by: cstsang
3 Replies
CHECKBASHISMS(1)                                              General Commands Manual                                             CHECKBASHISMS(1)

NAME
checkbashisms - check for bashisms in /bin/sh scripts SYNOPSIS
checkbashisms script ... checkbashisms --help|--version DESCRIPTION
checkbashisms, based on one of the checks from the lintian system, performs basic checks on /bin/sh shell scripts for the possible presence of bashisms. It takes the names of the shell scripts on the command line, and outputs warnings if possible bashisms are detected. Note that the definition of a bashism in this context roughly equates to "a shell feature that is not required to be supported by POSIX"; this means that some issues flagged may be permitted under optional sections of POSIX, such as XSI or User Portability. In cases where POSIX and Debian Policy disagree, checkbashisms by default allows extensions permitted by Policy but may also provide options for stricter checking. OPTIONS
--help, -h Show a summary of options. --newline, -n Check for "echo -n" usage (non POSIX but required by Debian Policy 10.4.) --posix, -p Check for issues which are non POSIX but required to be supported by Debian Policy 10.4 (implies -n). --force, -f Force each script to be checked, even if it would normally not be (for instance, it has a bash or non POSIX shell shebang or appears to be a shell wrapper). --extra, -x Highlight lines which, whilst they do not contain bashisms, may be useful in determining whether a particular issue is a false posi- tive which may be ignored. For example, the use of "$BASH_ENV" may be preceded by checking whether "$BASH" is set. --version, -v Show version and copyright information. EXIT VALUES
The exit value will be 0 if no possible bashisms or other problems were detected. Otherwise it will be the sum of the following error val- ues: 1 A possible bashism was detected. 2 A file was skipped for some reason, for example, because it was unreadable or not found. The warning message will give details. SEE ALSO
lintian(1). AUTHOR
checkbashisms was originally written as a shell script by Yann Dirson <dirson@debian.org> and rewritten in Perl with many more features by Julian Gilbey <jdg@debian.org>. DEBIAN Debian Utilities CHECKBASHISMS(1)
All times are GMT -4. The time now is 05:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy