Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

Need Help Writing Unix Script - URGENTLY

I need help writing a Unix Script, using Korn Shell (#!/usr/bin/ksh).

Basically, the script reads a file with the filename CAL_yyyymmdd  (yyyymmdd changes everyday).

In the CAL_yyyymmdd file, the script needs to skip the first line of text and starts reading the second line. The script should first check the third column (which states C or F).

If the second line, third column reads a C, then it takes the date from the second column from the right (missing out the C), the value 20090220 and it puts this value into a file called tom.dat.

If the script reads the second line, third column and finds its a F, it then continues to move on to the next line, third column.

When it reads the next line, third column and finds a C, the script should take the date from the second column, from the right (missing out the C), take the value 20090223 and write it to a file called dayaftertom.dat.

Once the script has read the second C from the third column, it should quit. This script is to take tomorrow's date and the date of the day-after-tomorrow and write it out to a file.

I've attached the file from which the Script needs to read its data from.

011060                8A20090220160040                      
011100                852009022016004020090220C C                                          120090225
011100                852009022016004020090221C F                                          000000000
011100                852009022016004020090222C F                                          000000000
011100                852009022016004020090223C C                                          120090226
011100                852009022016004020090224C C                                          120090227
011100                852009022016004020090225C C                                          120090302



CALENDAR-20090219.txt
0
ben1211
Asked:
ben1211
  • 4
  • 2
  • 2
  • +1
3 Solutions
 
ozoCommented:
so we want the first line that contains a C in the 3rd column?

awk '$3=="C"{print substr($2,17,8);exit}' CAL_`date +%Y%m%d` > tom.dat
0
 
TintinCommented:
Your specifications are a little unclear.

According to your specs, if the second line, 3rd column contains an F then skip it until the 3rd column contains a C and write the date to dayaftertom.dat.  Does the 2nd occurance of C also get written to dayaftertom.dat?
0
 
ben1211Author Commented:
Tintin....the first occurance of C from the 3rd column will take the date from the second column from point 17-24 (20090220) and write it to file tom.dat.  

{Note tht 17-24 is from the string of characters from the second column 852009022016004020090220C. So counting from left to right the date 20090220, will start from point 17-24)

The second occurance of C is then checked from the 3rd Column. Once this criteria is met, it read the second column, reading position 17-24 and writing the value to dayaftertom.dat.


Ozo...could you explain your script please? I do not want to merely just copy, but I would like to learn what its doing.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ben1211Author Commented:
Ozo....can't seem to run your script. Not getting any result at all.
0
 
ozoCommented:
did you look in tom.dat?
did   the CAL_`date +%Y%m%d` file for today contain what you posted?
0
 
TintinCommented:
OK, that's clarified and simplied things.


#!/bin/ksh
FILE=CAL_`date +%Y%m%d`
awk '$3=="C"{print substr($2,17,8)}' $FILE | head -1 >tom.dat
awk '$3=="C"{print substr($2,17,8)}' $FILE | sed -n 2p >dayaftertom.dat

Open in new window

0
 
ben1211Author Commented:
Tintin....I need the script to read yesterday's date
0
 
ahoffmannCommented:
> .. I need the script to read yesterday's date
and in your question you stated:
> This script is to take tomorrow's date ..

Could you come over with an unambigious description.
0
 
ben1211Author Commented:
My apologies. I made a mistake. It has to be yesterday's date. I'm sorry I didn't reply sooner.
0
 
ahoffmannCommented:
awk '((NR>1)&&($3=="C")&&(c<2)){c++;print substr($2,17,8)}'  CAL_`env TZ=GMT+24 date +%Y%m%d`
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now