need date in awk (Part II)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need date in awk (Part II)
# 1  
Old 09-16-2004
need date in awk (Part II)

Hello:

You guys were able to solve a similar problem for me yesterday...I was hoping I could get some assistance with this one as well.

I'm writing a bourne shell script in an old machine running TOPIX. Here's what the script looks like:

===========================================

LOG=/archive/logs/sys/alarm.log
today=`date +'%m/%d/%y %T'`

cat $LOG | grep SWI100 | sort | uniq -c | awk -v today="$today" '{print today "MSP\t" "Rich\t" $3 $12 "\t" $1}'

===========================================

I was able to get this to work yesterday in a Solaris box using /usr/xpg4/bin/awk instead of regular awk. However, I cannot do that in the TOPIX box as it does not have /usr/xpg4/bin/awk.

Of course, the script is not working properly (I do not get my timestamp)and I get the following error, followed by the remaining information (which is correct)

awk: syntax error at source line 1
context is today=09/16/04 >>> 13: <<<
awk: bailing out at source line 1
MSP Rich SWI110CLLICODE=OCQNVAXADS0 2

I checked man pages (in the TOPIX machine), and did not see anything about the -v option. I have tried every variation of syntax that I can think of.

Any suggestions??

-cd
# 2  
Old 09-17-2004
I have no clue what TOPIX is but see if the nawk command has the -v option - nawk should work like awk.
# 3  
Old 09-17-2004
TOPIX is a UNIX compliant operating system...stands for Transaction Oriented UNIX. It is almost identical to standard UNIX.

-cd
# 4  
Old 09-19-2004
The RTM idea was :
Do you have NAWK on your system?
# 5  
Old 09-21-2004
I do not have NAWK on my system.
# 6  
Old 09-21-2004
It's hard to guess what might work on this topix system. Maybe this...

cat $LOG | grep SWI100 | sort | uniq -c | awk '{print'"$today"' "MSP\t" "Rich\t" $3 $12 "\t" $1}'

Get the quoting exactly as I have it. You may need to cut and paste. Even then, there is no guarantee.
# 7  
Old 09-21-2004
try this, perhaps it will work :

awk -v today="$today" '{printf today" MSP\t" "Rich\t" $3 $12 "\t" $1}'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract date and time part from filename

Hi, I am facing one scenario in which I need to extract exact position of date and time from the name of the files. For example, Below is the record in which I need to extract position of YYYYMMDD,HHMISS and YYMMDD. Date and time variables can come more than once. I need to use these position... (13 Replies)
Discussion started by: Prathmesh
13 Replies

2. UNIX for Dummies Questions & Answers

Extract Date part from the filename

Hi All, I have incoming source files abcmmyy.txt I need to extract the mmyy part from the filename and pass that to a variable . I really appreciate your quick response on this. Thanks raj (7 Replies)
Discussion started by: rajeevm
7 Replies

3. UNIX for Dummies Questions & Answers

How to get year part from file created date?

Hi Gurus, I need to get year part of file created date. when using ls -l , it only show month, day and time. is there any option I can add to get year portition? Thanks in advance (7 Replies)
Discussion started by: ken6503
7 Replies

4. Shell Programming and Scripting

How do I take out(remove) the date part in the file name in a script?

Hi All, I need to create links between two directories. have multiple files in a specified location. Source Location ex: /opt/xdm/input/ Target Location ex: /opt/xdm input file names: 1. abc_app.aus.apac.yyyymmdd.dtd 2. abcd_app.aus.apac.yyyymmdd.dtd I need to build a code that reads... (1 Reply)
Discussion started by: kthri_82
1 Replies

5. Shell Programming and Scripting

How to remove the date part of the file?

Hi Gurus, I have file name like: abcd.20131005.dat I need to remove mid part of data final name should be abcd.dat thanks in advance (2 Replies)
Discussion started by: ken6503
2 Replies

6. Shell Programming and Scripting

Getting the date part from the log file.

Hi, I have a script that runs to generate a log file which is in this format: Start: Friday, April 29, 2011 18:30 User : Host : Database : I need to write a script that reads this log file (RUN.LOG) and rename the existing log file... (7 Replies)
Discussion started by: ashok@119
7 Replies

7. Shell Programming and Scripting

how to update date part with new increment date time

hi experts, my requirement is like this i need to develop a shell script to update date part with new incremental date time in file some 'X' which is kept at some server location incrementing every two hours.as i am new to this scripting i need support from u people,thanx in advance (1 Reply)
Discussion started by: amanmro
1 Replies

8. Shell Programming and Scripting

Execute a part of shell script only after particular date and time

I have created a simple shell script... say test.sh Contents of test.sh ================ service named restart cp /etc/imp.conf /backup/test/ #-- if date > 15 July 2007 11:23 pm , then only issue the commans below, else exit --- cp /etc/secondimp.conf /backup/test/ rm -f... (2 Replies)
Discussion started by: fed.linuxgossip
2 Replies

9. HP-UX

How do I take out(remove) the date part in the file name?

Hi Guys here I am again, I have two files in a specified location. Location ex: /opt/xdm/input/ input file names: 1. abc_app.yyyymmdd.dtd 2. abd_app.yyyymmdd.dtd I need to build a code that reads the files from the location based on the oldest date and cuts the date part... (5 Replies)
Discussion started by: ruthless
5 Replies

10. Shell Programming and Scripting

Add Date as part of file name

How can I add date in format yyyymmdd to my existing file name ? For example my file name is test.dat then i want it to be test.datyyyymmdd (3 Replies)
Discussion started by: amsh76
3 Replies
Login or Register to Ask a Question