Visit Our UNIX and Linux User Community


Using AWK to format output and email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using AWK to format output and email
# 1  
Old 05-24-2012
Using AWK to format output and email

Hello,

I'm a bit stumped, for some reason when using AWK 'print' is not printing the entire date/line.

Code:
awk '{print "Ticket #: " $1}
         {print "Queue : " $2}
         {print "Recieved : " $3}
         {print "AP Date : " $4}
         {print "Circuit ID : " $5}
         {print "Customer Name : " $6}' $FBLOG >$FBLOG.1

In the issue is the "Customer Name" for some reason its only printing the first word of the customer name.

Example ...

If the customer name is "ABC Company", it will only print "ABC"


Any help is apprieciated,
# 2  
Old 05-24-2012
awk by default separates fields on whitespace. How is it supposed to tell a 'good' space you do want, apart from a 'bad' space you don't want? Your customer is getting broken into fields $6, $7, $8...

I'd try this in shell instead, which can be told to do a limited amount of splitting. Since there's no fields beyond CUSTOMER, everything after that point will go into the CUSTOMER variable.

Code:
while read TICKET QUEUE RECEIVED APDATE CIRCUIT CUSTOMER
do
        echo "Ticket # $TICKET"
        echo "Received $RECEIVED"
        ...
done < $FBLOG > $FBLOG.1

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 05-24-2012
Hi
Please provide a sample input file to understand the input better. With what you have put, the output seems to be in the expected lines. Since there is a space between the first and the last name, it will be treated as two separate fields meaning ABC is $6 and company as $7.

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 4  
Old 05-24-2012
default separator for awk if space. So your 6th field is "ABC" and 7th is "Company".
Print 6th and 7th both while pulling Customer Name
This User Gave Thanks to 47shailesh For This Post:
# 5  
Old 05-24-2012
You guys rock! .... i didn't realize that the default separator for awk is "space"

I revised the code to now read as

Code:
{print "Customer Name : " $6, $7, $8}' $FBLOG >$FBLOG.1

and it works !

Previous Thread | Next Thread
Test Your Knowledge in Computers #518
Difficulty: Medium
Neither integer nor floating point numbers can represent every possible number since they use a finite number of bits to represent the number.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX command output format in email is not same as on the system

Hi I have script to collect file system usage statistics from few remote unix hosts and email . On the UNIX system the column spacing is fine but the email output is not aligned properly. Any tips to fix this ? (1 Reply)
Discussion started by: new2prog
1 Replies

2. Shell Programming and Scripting

Email Format Output issues

Hi Guys, I have written a script, which output information from email notfication. The output works fine in HTML format, but non-html format it is not shown in a human readable format. Can you help with the format *** Script echo " Server Name : $CLIENT_CHECK "... (4 Replies)
Discussion started by: Junes
4 Replies

3. Shell Programming and Scripting

Format output using awk

Hello all , need help with this ... Input File DEV % POOL 0CB4 FBA 2211300 81792 4 IE RAID-5(3+1) R5_EFD100_1 - - 1805376 82 IF RAID-1 M2_FC300_1 - ... (4 Replies)
Discussion started by: greycells
4 Replies

4. UNIX for Dummies Questions & Answers

after awk-> format output

hi i have a awk command with several querys.... awk 'FS="|""; print $4, $5, $6...etc.... $4 gives me the date 20120304 $5 is timestamp 101023 I want to format these in 2012.03.04 or 2012/03/04 10:10:23 but have no idea, if this is possible with format-parameters in the awk... (2 Replies)
Discussion started by: Jazzmatazz
2 Replies

5. Shell Programming and Scripting

Format the output to sent in Email

Hi I have a script #!/bin/sh # email addresses to send results to, separated by a space EMAILS="xxxx.yyyy@yahoo.com" SUBJECT="MySQL reporting " DISK_DATA_USAGE=/home/aaaa/usaage.txt mysql YYYYYYYY -e " select 100*sum(max_data_length) as disk_usage_pct from xxxxxx;" >... (2 Replies)
Discussion started by: asha210
2 Replies

6. Shell Programming and Scripting

awk to format an output

awk experts, I have in put file with time stamp followed by "," separated data. same patern continues. The output need time stamp in first columns and data total in 2nd columns. Input file T 9:15 d0,1,3,3 d1,2,1,1 d2,3,1,5 e1,1,1,1 T 9:30 d0,1,1,1 d1,2,3,2 d3,1,2,1... (10 Replies)
Discussion started by: arv_cds
10 Replies

7. Shell Programming and Scripting

awk - format output

Input file1 zone: BAU_SERVER1 C0:50:76:01:C6:20:00:12; 50:06:01:69:3B:20:14:8B; 50:06:01:60:3B:20:14:8B zone: BAU_SERVER2 C0:50:76:01:C6:20:00:08; 50:06:01:69:3B:20:14:8B; 50:06:01:60:3B:20:14:8B zone: ... (4 Replies)
Discussion started by: greycells
4 Replies

8. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

9. Shell Programming and Scripting

[need help] output format from awk

hi all, i have a problem with my nawk command output below is the description : nawk $12 == "00008001" { cnt++;cs_cd } END {for(cd in cs_cd) print cd, cs_cd } 2007020814.TDR output : 133 123 desire output: 133,123,.... please advices thank you so much (6 Replies)
Discussion started by: bucci
6 Replies

10. Shell Programming and Scripting

Output in a particular format using AWK

Hi All, I am trying to check if if column 5 is greater than 90. If greater it will print the term in column 6, else if all are within limit, then it will output "Size is within limit". I can't seem to do that with the below code. The output should only be 1 statement of "Size is within the... (4 Replies)
Discussion started by: Raynon
4 Replies

Featured Tech Videos