Newbie problem with ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Newbie problem with ksh script
# 8  
Old 02-21-2006
Quote:
Originally Posted by sabercats
So you mean
for file in *dat; do
YYYYMMDD=grep "|" $file | nawk -F"|" '{split(substr($2, 1, index($2, " ")-1), t, "-") | print t[3] t[1] t[2]}'

It did not work Smilie
what I meant was related to the original question:
Quote:
Originally Posted by sabercats
In .dat file the DATE Field is $2 and and have mm-dd-yyyy hh:mm:ss
like 02-21-2006 12:05:06 , how do I get only 20060221
# 9  
Old 02-22-2006
Quote:
So you mean
for file in *dat; do
YYYYMMDD=grep "|" $file | nawk -F"|" '{split(substr($2, 1, index($2, " ")-1), t, "-") | print t[3] t[1] t[2]}'
It did not work
since your variable wasn't correct, you missed to open quotes before the grep..

Code:
YYYYMMDD=`grep "|" $file | nawk -F"|" '{split(substr($2, 1, index($2, " ")-1), t, "-") | print t[3] t[1] t[2]}`

# 10  
Old 02-22-2006
Quote:
Originally Posted by Anubhav
It did not work
since your variable wasn't correct, you missed to open quotes before the grep..

Code:
YYYYMMDD=`grep "|" $file | nawk -F"|" '{split(substr($2, 1, index($2, " ")-1), t, "-") | print t[3] t[1] t[2]}`

I don't think you copied the original 'nawk' suggestion correctly. Pay closer attention to the matching ' characters AND to the ';' character in the 'nawk' statement.

Suggestion:
copy/paste the original suggestion and see if it works as is. Next try to adopt to your specific needs.
# 11  
Old 02-22-2006
I tried with a line, then when I put it in, it give me the error Smilie, that's why I asked what did i do wrong ?


Syntax Error The source line is 1.
The error context is
{split(substr($2, 1, index($2, " ")-1), t, "-") | >>> print <<< t[3] t[1] t[2]}
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.

# 12  
Old 02-22-2006
Here is my code for my problem, please help me point out inccorect code

#!/bin/ksh -x

cd /DATA/
for file in *.dat; do
# Try to get date to create file name.
RUNDATE=`grep "|" $file | nawk -F"|" '{split(substr($2, 1, index($2, " ")-1), t, "-") | print t[3] t[1] t[2]}`



ALINES=$(cat ${RUNDATE}.dat | wc -l)
BFIRST=$(head -1 ${RUNDATE}.stat)

IFS=\'
set -- $BFIRST
BLINES=$2

if (( ALINES == BLINES ))
then
print "Records count is matched"
else
print "Records count is not matched"
fi


AFIRST=$(head -1 ${RUNDATE}.dat)
BTHREE=$(cat ${RUNDATE}.stat | sed -n 2p)
if [ ${AFIRST} = ${BTHREE}];
then
print "First record is matched"
else
print "First record is not matched"
fi


ALAST=$(tail -1 ${RUNDATE}.dat)
BFOUR=$(cat ${RUNDATE}.stat | sed -n 3p)
if [ ${ALAST} = ${BFOUR} ]
then
print "Last record is matched"
else
print "Last record is not matched"
fi

grep "|" ${RUNDATE}.dat |

sort -t"|" +1 -2|

awk -F"|" '{
if ($2 != "") {
name = $1;
datetime = $2;
studentid = $6
class = $7;
printf"%s|%s|%s\n",name,studentid,class;
}


}' |


sort -t, +0 -1 >> /NEW/DATA/log-${RUNDATE}.dat

done



Thanks,

Last edited by sabercats; 02-22-2006 at 05:58 PM..
# 13  
Old 02-22-2006
Quote:
Originally Posted by sabercats
I tried with a line, then when I put it in, it give me the error Smilie, that's why I asked what did i do wrong ?


Syntax Error The source line is 1.
The error context is
{split(substr($2, 1, index($2, " ")-1), t, "-") | >>> print <<< t[3] t[1] t[2]}
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.

as i said previously......
Quote:
Originally Posted by vgersh99
Pay closer attention to the matching ' characters AND to the ';' character in the 'nawk' statement.
Simply 'copy/paste' my ORIGINAL suggestion.
# 14  
Old 02-22-2006
I am lost, i added ; but it did not work .... how dump am i Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script newbie, what is problem with my script?

Hello, Ubuntu server 11.10 can anybody help what is problem with my shell script? #!/bin/bash #script to find out currently logged on user is root or not. if ] then echo "You are super" else echo "You are awesome!" fi When I run script, I get following output ./uid: line 3: I... (4 Replies)
Discussion started by: kaustubh
4 Replies

2. UNIX for Dummies Questions & Answers

problem in Executing script in ksh

Hi, I am in ksh. below mentioned 3 commands I executed at command prompt & got the expected results. csh source csh_infa <special command> Now I have to do this in the script in ksh. I entered it as it is. #!/bin/ksh csh source csh_infa <special command> Now after... (1 Reply)
Discussion started by: girish_kanak
1 Replies

3. Shell Programming and Scripting

newbie: writing ksh shell problem

my default profile is using ksh, I tried to write a simple scripts and I had issues, below is my scripts: $ more if_num.ksh USAGE="usage: if_num.ksh" print -n "Enter two numbers: " read x y if ((x=y)) then print "You entered the same number twice." when I tried to executed the... (6 Replies)
Discussion started by: matthew00
6 Replies

4. Shell Programming and Scripting

Newbie problem with simple script to create a directory

script is: dirname= "$(date +%b%d)_$(date +%H%M)" mkdir $dirname should create a directory named Nov4_ Instead I get the following returned: root@dchs-pint-001:/=>./test1 ./test1: Nov04_0736: not found. Usage: mkdir Directory ... root@dchs-pint-001:/=> TOO easy, but what am I... (2 Replies)
Discussion started by: gwfay
2 Replies

5. UNIX for Dummies Questions & Answers

script sourcing problem (ksh)

I have a script "abc.sh" in /tmp which has exit 0 as its last line when I run this script from /tmp/xyz/def.sh script as . ../abc.sh then the script executes but the control doesn't return to def.sh script for subsequent commands in def.sh but if I invoke the abc.sh from inside the... (3 Replies)
Discussion started by: rakeshou
3 Replies

6. Shell Programming and Scripting

A newbie with a problem in A date Script

Hello everybody... I'm a Unix newbie and i just got this task at work to figure out what's wrong with a daily script my team is using. The idea behind the script is that it takes the day before in a yyyymmdd format, find files with that date in a specific directory and executes an (irrelavant)... (4 Replies)
Discussion started by: adija
4 Replies

7. 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

8. Shell Programming and Scripting

Newbie convert date ksh

If I have start = 02282006; end = 03152006; How do I get startdate = 02/28/2006; enddate = 03/15/2006; Thanks, (3 Replies)
Discussion started by: britney
3 Replies

9. Shell Programming and Scripting

KSH Script/FTP (NEWBIE)

I trying to write a ksh script (without the help of the Kermit libraries) which connects to a ftp server and checks if the file "KEI.done" exists. If the file exists it print "files is there" if it doesnt exist it prints "file is not there". (the print statements will later be replaced with code to... (2 Replies)
Discussion started by: mike509123
2 Replies

10. Shell Programming and Scripting

ksh script and java problem

I have a problem with the execution of a ksh as deamon on linux. I explain you first the context. We have developped a Java program that execute every minutes an external (that we don't have developped) program with a config file in parameter. The Java program is runned as deamon with a perl... (0 Replies)
Discussion started by: adrian.mihai
0 Replies
Login or Register to Ask a Question