awk question for printing variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk question for printing variables
# 1  
Old 09-24-2012
awk question for printing variables

Hi All,
I have the following awk code where I am passing 4 variables to the program and I need to print them in the awk script.
The variables are $start_month $start_date - $end_month $end_date.

Code:
printf("\tFor More Information\n") > out_tmp1
printf("\tIf you have any questions about this letter, please call Customer\n") > out_tmp1 
printf("\tRelations at 1-800-701-95677 (TTY 1-800-234-9232).  Representatives\n") > out_tmp1 
printf("\tare available Monday - Friday, 8:00 a.m. - 8:00 p.m. (Representatives\n") > out_tmp1
printf("\tare available 7 days a week, 8:00 a.m. - 8:00 p.m. from \n") > out_tmp1
printf("\t %s %s %s %s $start_month $start_date - $end_month $end_date.) After hours and on holidays,\n") > out_tmp1 
printf("\tplease leave a message and a representative will return your call on\n") > out_tmp1
printf("\tthe next business day.\n") > out_tmp1
printf("\t\n") > out_tmp1

I would appreciate if someone can lt me know the right way of doing it.
# 2  
Old 09-24-2012
you can pass variable like this..

Code:
awk -v SM="$start_month" -v SD="$start_date" -v EM="$end_month" -v ED="$end_date" '{print SM,SD,EM,ED}' file

# 3  
Old 09-24-2012
Yes. I have passed the variables from shell script to awk.It's the printing from awk that is a problem.

Is this correct ?

Code:
printf("\t %s %s %s %s $start_month $start_date - $end_month $end_date.) After hours and on holidays,\n") > out_tmp1

# 4  
Old 09-24-2012
just see above in my example...
# 5  
Old 09-25-2012
google : printf awk
first result : Printf Examples - The GNU Awk User's Guide

moreover a ">" delete the file and write the line. So if you want to add a line you must use ">>"
# 6  
Old 09-25-2012
Appreciate the help! But I am facing syntax issues.Can someone help please.I am sending 4 variables SM,SD,EM,ED through a shell script to the awk file.

Code:
printf {"\t%s %s %s %s\n", "$SM,$SD,"-"$EM,$ED" After hours and on holidays,\n") > out_tmp1 

printf("\t"8:00 a.m. - 8:00 p.m. (From" "%s %s %s %s\n", $SM,$SD,"-"$EM,$ED" "representatives"\n") > out_tmp1

# 7  
Old 09-25-2012
Quote:
Originally Posted by nua7
Appreciate the help! But I am facing syntax issues.Can someone help please.I am sending 4 variables SM,SD,EM,ED through a shell script to the awk file.

Code:
printf {"\t%s %s %s %s\n", "$SM,$SD,"-"$EM,$ED" After hours and on holidays,\n") > out_tmp1 

printf("\t"8:00 a.m. - 8:00 p.m. (From" "%s %s %s %s\n", $SM,$SD,"-"$EM,$ED" "representatives"\n") > out_tmp1

it's already been answered in the current thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echo not printing the variables with delimiters as required

This is the file which contains only neccessary values from the output of curl command i.e TEMP_FILE Proxy Hostname server0123.domain.com Proxy IP address XXX.XXX.XX.XX port 0000 Proxy Version SGOS X.X.X.X Proxy Serial # ... (5 Replies)
Discussion started by: ramprabhum
5 Replies

2. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

3. Shell Programming and Scripting

awk question ? set 2 variables by matching fields

Hello, I'm trying to get the TOP and BASE numbers printed out File looks like this: 2300 CAR # 2300 is the TOP 2310 CAR 2335 CAR 2455 CAR # 2455 is the BASE 1000 MOTOR # 2455 will become this TOP 2000 MOTOR 3000 MOTOR 4000 MOTOR # 4000 is the BASE 2345 BIKE # 4000... (8 Replies)
Discussion started by: charlieglen
8 Replies

4. UNIX for Dummies Questions & Answers

awk printing question

im using awk as a part of my tasks to filter out stuff for reporting details in our storage environment, supposed i filtered out these details (sorry, this might be long.) bash$ > for x in 1 2; do symdg show floras0-snap$x | awk '{print $3,$4}'; done : REGULAR in GNS Yes :... (10 Replies)
Discussion started by: prodigy06
10 Replies

5. Shell Programming and Scripting

Awk variables not printing to StdOutput

Hi guys, I'd be grateful if you could have a look at my code below and give me some feedback as to why the homedir and fullname variables aren't being printed to Standard Output when the script is run. Many thanks. read -p "Please type in username you wish to get information from: " username ... (6 Replies)
Discussion started by: jjb1989
6 Replies

6. Shell Programming and Scripting

Help with awk: printing variables

awk is only printing out the variables on the first AK2, how do I get it to print out the variables for every occurrence of AK2? grep -l "^ST.997" *.replaced|sort -n|uniq>FILELIST while read file do let "count = $count+1" <$file awk 'BEGIN { FS="" ... (0 Replies)
Discussion started by: verge
0 Replies

7. Shell Programming and Scripting

awk multiline with 1 or more variables (question)

am trying to grab the fields marked in red for monitoring purposes. each vfiler can have anywhere from 0-50 Path(s). in order to get here i run the following for filer in `cat filers.list` ; do ssh $filer vfiler status | awk '{print $1}' ; done this returns vfiler0 vfilert vfiler2 ... (2 Replies)
Discussion started by: riegersteve
2 Replies

8. Shell Programming and Scripting

Awk/shell question: Read from file and assign to variables.

Is anyone able to help with writing a program that will do the following: 1. Read the contents of a file, line by line, and on each line, assign each of the two columns to a shell variable. 2. perform an action on the variables 3. Read the next line. Here is what I've gotten so far. ... (3 Replies)
Discussion started by: akbar
3 Replies

9. UNIX for Dummies Questions & Answers

Silly question on printing for loop in AWK

Hi, One silly question. I would like to add statement like below and append to a file. I used the below code; however, it does not work. Can anyone please tell me what mistakes I have made? awk ' { for (i=1;i<=563;i++) print i }'>>output.txt Thanks. -Jason (1 Reply)
Discussion started by: ahjiefreak
1 Replies

10. AIX

Stupid printing question

I am in the process of migrating software from HP-UX to AIX 5. On the HP box, instead of printing directly to the printer, we piped everything through a ksh script to set the printing parameters (such as landscape/portrait, 12.5 cpi, duplex, etc, etc) via the "-o" option. Since we move printers... (0 Replies)
Discussion started by: Highness
0 Replies
Login or Register to Ask a Question