It looks like the line is too long for your shell.
If you can change shell to bask just to try the command it would be good.
It looks like the line is too long for your shell.
If you can change shell to bask just to try the command it would be good.
Reborg,
How can I change the shell to bask. Is it not advisable to keep the script in ksh and run?
Kindly suggest.
Are you running currently this in a script or from the command line?
Reborg,
I am running this from command line presently.
ok, just type bash to switch to bash, and run the command. That should allow you to confirm that the syntax does what you want.
Reborg,
I think bash is not installed on my server. It says
sh: bash: not found
So I think the only option is script right!!! But even the script may not work as it can't accept that many lines in a single line. Kindly suggest.
Reborg,
I have copied this entirely into a script file and tried to execute it. But I am getting this error I got before.
I copied correctly into the .ksh file
The error as follows:
Below is the script file and error below: i don't know where I am going wrong.
awk '{data[FNR] = $0; out=CARE01_DLY_???_date+%Y%m%d"_new";
file[FNR]=out;} END { if ( FNR - 2 == $1) { for ( i=2 ; i < FNR; i++ ) {
print data > file[i]} close(file[i])}else { print "error"} }'
CARE01_DLY_???_date+%Y%m%d
syntax error The source line is 1.
The error context is
{data[FNR] = $0; >>> out=CARE01_DLY_?? <<<
awk: The statement cannot be correctly parsed.
The source line is 1.
Please suggest.
awk '{data[FNR] = $0; out=FILENAME "_new"; file[FNR]=out;} END { if ( FNR - 2 == $1) { for ( i=2 ; i < FNR; i++ ) { print data > file} close(file)}else { print "error"} }' CARE01_DLY_???_`date+%Y%m%d`
I'll try this again...this is the code, do not change ANYTHING, just copy and paste it, exactly as it is, into your script, do not edit any of the code.
Reborg,
I got this new error message: I have full permission on the file.
awksatya.ksh[2]: dev: not found
./awksatya.ksh[5]: dev: not found
./awksatya.ksh[7]: date+%Y%m%d: not found
awk: Cannot find or open file CARE01_DLY_???_.
The source line number is 1.
Here is the code:
awksatya.ksh
#!/bin/ksh
dev = /biddf/ab6498/dev/ctl
export dev
cd dev
awk '{data[FNR] = $0; out=FILENAME "_new"; file[FNR]=out;} END { if (
FNR - 2 == $1) { for ( i=2 ; i < FNR; i++ ) { print data > file}
close(file)}else { print "error"} }' CARE01_DLY_???_`date+%Y%m%d`
Please use code tags to show code.
There were a couple of errors in you script.
In ksh you cannot use spaces in an assignment, the syntax is
var=value
Variable substitution is done by prefixing with $
cd $dev
In this case the variable does not need to be exported as it's only used in the current shell.
#!/bin/ksh
dev=/biddf/ab6498/dev/ctl
cd $dev
awk '{data[FNR] = $0; out=FILENAME "_new"; file[FNR]=out;} END { if (
FNR - 2 == $1) { for ( i=2 ; i < FNR; i++ ) { print data > file}
close(file)}else { print "error"} }' CARE01_DLY_???_`date +%Y%m%d`
Reborg,
Sorry that I didn't use code tags. I will use from now on.
I am still getting this error. I did have full privileges on the file though.
awksatya.ksh[2]: dev: not found
./awksatya.ksh[7]: date+%Y%m%d: not found
awk: Cannot find or open file CARE01_DLY_???_.
The source line number is 1.
#!/bin/ksh
dev='/biddf/ab6498/dev/ctl'
cd $dev
awk '{data[FNR] = $0; out=FILENAME "_new"; file[FNR]=out;} END { if (
FNR - 2 == $1) { for ( i=2 ; i < FNR; i++ ) { print data > file}
close(file)}else { print "error"} }' CARE01_DLY_???_`date '+%Y%m%d'`
Thanks vgersh.
Vgresh/Reborg,
You guys are simply superb man. I bow to your UNIX skills and the integrity in which you are maintaining the site. I really appreciate your knowledge and skill set.
One more thing Reborg/Vgresh,
I am getting an error
awk: Cannot find or open file CARE01_DLY_???_20060720. I think its not taking the MKT characters in the file.
I have the file CARE01_DLY_MKT_20060720 in the directory /biddf/ab6498/dev/ctl But I don't know why this is showing as
CARE01_DLY_???_20060720. Does the pattern substitution not working in our code. Kindly suggest guys. We are almost there. Just one step away.
What does this print:
#!/bin/ksh
dev='/biddf/ab6498/dev/ctl'
cd $dev
echo CARE01_DLY_???_20060720
echo CARE01_DLY*20060720
set +noglob
echo CARE01_DLY_???_20060720
echo CARE01_DLY*20060720
Reborg,
It prints the following;
CARE01_DLY_MKT_20060720
CARE01_DLY_MKT_20060720
Current option settings
allexport off
bgnice off
emacs off
errexit off
gmacs off
ignoreeof off
interactive off
keyword off
markdirs off
monitor off
noexec off
noclobber off
noglob off
nolog off
nounset off
privileged off
restricted off
trackall on
verbose off
vi on
viraw off
xtrace off
./arun.ksh[10]: +noglob: bad option(s)
CARE01_DLY_MKT_20060720
CARE01_DLY_MKT_20060720
ok try this.
#!/bin/ksh -x
dev='/biddf/ab6498/dev/ctl'
cd $dev
files=CARE01_DLY_???_`date '+%Y%m%d'`
awk '{data[FNR] = $0; out=FILENAME "_new"; file[FNR]=out;} END { if (
FNR - 2 == $1) { for ( i=2 ; i < FNR; i++ ) { print data > file}
close(file)}else { print "error"} }' $files
Reborg,
I am still getting the error:
awk: Cannot find or open file CARE01_DLY_???_20060720.
Try with the what I posted previousy ( new edit in post on the first line)
Reborg,
What is new edit in post on the first line? Sorry I didn't get you.