error in awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error in awk command
# 8  
Old 05-07-2009
could you show a sample of your 'filename*.txt files?
# 9  
Old 05-07-2009
Hi Vgersh,

Firstof all Thanks again and again.

My Filename looks like this
filename.Y20090503.txt

I have such files in my directory as

filename.Y20090503.txt
filename.Y20090502.txt
filename.Y20090501.txt
filename.Y20090430.txt
filename.Y20090429.txt


I did the following:

v_RUN_DT=20090503
v_LOAD_DT=20090430

ls filename*.txt|awk -F".Y" 'int($2) < int(vr) && int($2) > int(vl)' vr="${v_RUN_DT}" vl="${v_LOAD_DT}"

OutputI am getting is:

filename.Y20090502.txt
filename.Y20090501.txt
filename.Y20090430.txt
filename.Y20090429.txt


But my output should be

filename.Y20090503.txt
filename.Y20090502.txt
filename.Y20090501.txt
filename.Y20090430.txt

Thank you
# 10  
Old 05-08-2009
Code:
ls filename*.txt | nawk -F'[.Y]' '$3 <= vr && $3 >= vl' vr="20090503" vl="20090430"

# 11  
Old 05-19-2009
Hi,

Can you tell me ...I have 02-MAY-2009 and 05-MAY-2009..How do I compare this dates... they are in date format. I tried

v_dt_1= 02-MAY-2009
v_dt_2= 05-MAY-2009

v_dt_1 < v_dt_2
also
v_dt_1 -ltv_dt_2
both doesnt work
# 12  
Old 05-19-2009
Code:
ls filename*.txt | nawk -F'[.Y]' '
BEGIN {
 mon="JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC"
   monN=split(mon, monA, "|");
   for(i=1; i<=monN; i++) {
     monA[monA[i]]=i;
     delete monA[i];
   }
}
function dat2num(dat,    n,datA,str)
{
     n=split(dat, datA,"-")
     str=datA[3] sprintf("%02d",monA[toupper(datA[2])]) sprintf("%02d", datA[1])
     return str
}

dat2num($3) <= dat2num(vr) && dat2num($3) >= dat2num(vl)' vr="05-MAY-2009" vl="02-MAY-2009"


Last edited by vgersh99; 05-19-2009 at 10:27 AM..
# 13  
Old 05-19-2009
RubinPat, (or is it henrysmith or aronmelon)

This is an example how to convert the date format from 02-MAY-2009 to 20090205:

Code:
echo '02-MAY-2009'|
awk 'BEGIN{
  split("JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC", month, " ")
  for (i=1; i<=12; i++) mdigit[month[i]]=i
}
{
  m=toupper(substr($1,4,3))
  dat=substr($1,8)substr($1,1,2) sprintf("%02d",mdigit[m])
  print dat
}'

With this example you should be able to adjust the code for your specific needs.
# 14  
Old 05-19-2009
Vgersh,

Thats what I want but I dont need to list the file names here I have

v_dt1= 02-MAY-2009
v_dt2= 05-MAY-2009

Just need to compare v_dt1 < v_dt1

get stuck at error message:

The specified number is not valid for this command.

Just pls guide me...Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

awk command error in Solaris

I have the following code that works perfectly in Cygwin $ awk -F, ' BEGIN {months ="AP01"; months ="AP02"; months ="AP03"; months ="AP04"; months ="AP05"; months ="AP06"; months ="AP07"; months ="AP08"; months ="AP09"; months ="AP10"; months ="AP11"; months... (3 Replies)
Discussion started by: Raul_Rodriguez
3 Replies

2. Shell Programming and Scripting

Spot error with my awk command

can any one identify why this command keeps resulting in 1, even though the string i'm searching for actually does not exist in the log? awk 'BEGIN{count++} NR>220 && NR<=223 && /error/ && !/No.*such.*file.*or.*direfctory/ { count++ } END { print count }' /var/log/mail.log i expected it to... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

Bash script with awk command ERROR

Hello im new here... Im trying to read file and create folders from words in it but i get this for loop error awk : line 3 : syntax error at or near for my code is.. #!/bin/bash begin for (( i=1;i<=5;i++)); do awk -v i=$i $0 { print $i } mkdir $i done {print $i} end {} i have... (7 Replies)
Discussion started by: boxstep
7 Replies

4. Shell Programming and Scripting

Pass awk field to a command line executed within awk

Hi, I am trying to pass awk field to a command line executed within awk (need to convert a timestamp into formatted date). All my attempts failed this far. Here's an example. It works fine with timestamp hard-codded into the command echo "1381653229 something" |awk 'BEGIN{cmd="date -d... (4 Replies)
Discussion started by: tuxer
4 Replies

5. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

6. Shell Programming and Scripting

Getting syntax error while running awk command

Hello Gurus, I am firing the below command : df -g | grep -v var| awk '{ (if $4 > 90% ) print "Filesystem", $NF,"over sized";}' But I am getting the below error:- ====== syntax error The source line is 1. The error context is {if ($4 > >>> 90%) <<< awk: The... (9 Replies)
Discussion started by: pokhraj_d
9 Replies

7. Shell Programming and Scripting

Multiple command execution inside awk command during xml parsing

below is the output xml string from some other command and i will be parsing it using awk cat /tmp/alerts.xml <Alert id="10102" name="APP-DS-ds_ha-140018-componentFailure-S" alertDefinitionId="13982" resourceId="11427" ctime="1359453507621" fixed="false" reason="If Event/Log Level(ANY) and... (2 Replies)
Discussion started by: vivek d r
2 Replies

8. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

9. Shell Programming and Scripting

Error passing parameter in "sub" command in awk

I have to replace the pattern found in one file in another file with null/empty "" if found on the fields 3 or 4 ONLY File 1 ==== 10604747|Mxdef|9999|9999|9999|2012-03-04 00:00:59 10604747|Mcdef|8888|9999|8888|2012-03-04 00:00:59 . . . File 2 ==== 9999 8888 . . . Expected... (7 Replies)
Discussion started by: machomaddy
7 Replies

10. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies
Login or Register to Ask a Question