Help with awk cmd


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk cmd
# 1  
Old 09-14-2007
Help with awk cmd

Hi All,

I am trying to read a file as input and pull out some information from the file and put it into another file in column format and then take that file and make it an excel file. My problem is that I'm trying to put the date in one of the columns using a variable in an awk cmd, but when I do this I get some decimal number not the date. Can anyone help here is my code:

#!/bin/sh -x
# Script to pull out the tape number and expiration date from the Vault report file.

##########################################
FILEDIR=/usr/openv/netbackup/vault/reports

MONTH=`date +%b`
CURYEAR=`date +%Y`
NEXTYEAR=`expr $CURYEAR + 1`
TENYEAR=`expr $CURYEAR + 10`
IDATE=`date +%m/%d/%Y`

#This will find the latest summary file.#
FILE1=`ls -ltr $FILEDIR/summary_distlist_vault_??????????.rpt| awk '{ print $9 }' | sed -n '$p'`
OFFSITE=/tmp/offsite_tapes.xls
################################################################################################
# Remove the last offsite files before creating a new one.#
if [ -s $OFFSITE ];then
rm $OFFSITE
fi

cd $FILEDIR

# This should pars the latest file and pull out "MEDIA ID" and "EXPIRATION" and create the "$OFFSITE" file.#
cat $FILE1 | grep -Ev "$MONTH|full" | egrep "$CURYEAR|$NEXTYEAR|$TENYEAR" | awk '{ print "\t""\t"$2"\t""\t"$IDATE"\t"$3 }' > $OFFSITE
chmod 777 $OFFSITE

#Email the Excel file#
uuencode $OFFSITE offsite_tapes.xls | mailx -s "Offsite Tape Spreadsheet" email@something.com
##################################################

The red part is what's giving me the trouble. $IDATE is suppose to be the system date and I get a decimal number in the excel file. Thanks in advance for any help you can give me.Smilie
# 2  
Old 09-14-2007
Try

Code:
cat $FILE1 | grep -Ev "$MONTH|full" | egrep "$CURYEAR|$NEXTYEAR|$TENYEAR" | awk -v dt=$DATE  '{ print "\t\t"$2"\t\t"dt"\t"$3 }' > $OFFSITE

# 3  
Old 09-14-2007
Still not working.

Thank you Klashxx. I tried that and it didn't work. After the first set of numbers below should be the date ($IDATE) and then a blank column and then the the last set of numbers (expiration dates) at the end. Do you have another suggestion? Thanks again.

<blank here><blank here>1313<$IDATE here><blank here>3/10/2008
<blank here><blank here>1359<$IDATE here><blank here>3/10/2008

Last edited by New2Scripting; 09-14-2007 at 09:44 AM..
# 4  
Old 09-14-2007
I missed a letter:
Quote:
Originally Posted by Klashxx
Try

Code:
cat $FILE1 | grep -Ev "$MONTH|full" | egrep "$CURYEAR|$NEXTYEAR|$TENYEAR" | awk -v dt=$IDATE  '{ print "\t\t"$2"\t\t"dt"\t"$3 }' > $OFFSITE

# 5  
Old 09-14-2007
Thank you!!!

Thank you so much Klashxx it worked great. Smilie Smilie Smilie SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk cmd for vlookup in Mysql

Hi, Is there possible to do vlookup in Mysql one table from another table based on one column values and placed the data in same table? if it is possible in mysql itself pls share links for reference. Here is the ex: i need to vlookup the cus.id in table to and place the cus.name in 4th... (3 Replies)
Discussion started by: Shenbaga.d
3 Replies

2. Shell Programming and Scripting

Get the awk cmd for two condition

Hi All, i have following cmd to get a “n/a” value from one particular column, but if i need to take one column n/a value with based on other column this cmd will help? ex: col1 col2 col3 234 RR Yes n/a RR1 No 236 RR2 No 237 RR3 Yes 238 RR4 No n/a ... (1 Reply)
Discussion started by: Shenbaga.d
1 Replies

3. Shell Programming and Scripting

Invoking system(cmd) inside awk command

Hi, I was searching for a way to grep 2 lines before and after a certain keyword, and I came across the following code.. awk "\$0 ~ /ORA-/ { cmd=\"awk 'NR>=\" NR-2 \" && NR<=\" NR+2 \"' init.ora\" system(cmd) }" input_file I could not understand how this works. What is system() ? what... (2 Replies)
Discussion started by: Kulasekar
2 Replies

4. Shell Programming and Scripting

Awk: cmd. line:1: fatal: division by zero attempted

when i try the snippet in the console its working fine: ps awwwux | grep php-fpm | grep -v grep | grep -v master | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' output: but when i try the bash script: #!/bin/sh # -*- sh -*- #... (3 Replies)
Discussion started by: danieloooo
3 Replies

5. Shell Programming and Scripting

Perl open(CMD, "cmd |"); buffering problem..

Hello, There's a third-party application's command that shows the application's status like "tail -f verybusy.log". When use the command, the output comes every 1-sec. but when it goes in a script below the output comes every 8-sec...What is the problem and how can I fix it? open(CMD,... (2 Replies)
Discussion started by: Shawn, Lee
2 Replies

6. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

7. Shell Programming and Scripting

Capturing awk's system(cmd) output

Hi everybody, I am working on a bigger awk script in which one part is comparing the size of two files. I want to evaluate which file is bigger and then just save the bigger one. I got it all working except for the part where I want to figure out which file is bigger; the one awk is currently... (2 Replies)
Discussion started by: iMeal
2 Replies

8. Shell Programming and Scripting

Combining many lines to one using awk or any unix cmd

Combining many lines to one using awk or any unix cmd Inputfile: Output : Appreciate help on this. (14 Replies)
Discussion started by: pinnacle
14 Replies

9. HP-UX

awk to output cmd result

I was wondering if it was possible to tell awk to print the output of a command in the print. .... | awk '{print $0}' I would like it to print the date right before $0, so something like (this doesn't work though) .... | awk '{print date $0}' (4 Replies)
Discussion started by: IMTheNachoMan
4 Replies

10. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies
Login or Register to Ask a Question