Sponsored Content
Full Discussion: Printing awk outputs
Top Forums Shell Programming and Scripting Printing awk outputs Post 302969663 by EAGL€ on Friday 25th of March 2016 10:55:33 AM
Old 03-25-2016
Printing awk outputs

Hello All,

I have the following command which works partially:

Code:
gzcat *2016-03-25_*gz | gawk -F"|" '
BEGIN{format = "%-10s %-13s %-17s %-35s\n"; 
printf format, "EVENT_TYPE","RESPONSE_CODE","INTERNAL_ERR_CODE","FLOWNAME"; 
printf format, "----------", "-------------", "-----------------", "-----------------------------------"}
{if(( $5 == 2001 ) && ( $8 != 0 ) && ( $12 ~ "fulfillService" )) printf format, $5,$8,$9,$(NF-1)}' 
| sort | uniq -c

And its output is :

Code:
   1 ---------- ------------- ----------------- -----------------------------------
   2 2001       -2            100               refillVoucherless                  
   1 2001       -2            320001            deactivateBBService                
   1 2001       -3            -3                updateDataOfferSelectionRetrieve   
   2 2001       -3            104               refillVoucherless                  
5259 2001       -3            114               refillVoucherless                  
13482 2001       -3            115               refillVoucherless                  
   1 2001       -3            4020123           updateDataOfferSelection           
   1 2001       -4            1002              setHLRSub                          
  26 2001       -4            11111             addAndActivateService              
  12 2001       -4            13                setHLRSub                          
 267 2001       99            0                 updateDataOfferSelectionRetrieve   
   1 EVENT_TYPE RESPONSE_CODE INTERNAL_ERR_CODE FLOWNAME

I guess "Sorting" after gawk command does mix things up and cause the output which I don't want. How could I print output like the following? Should I get rid of Sort and use something inside gawk? if so I would appreciate your help very much.

Code:
   1 EVENT_TYPE RESPONSE_CODE INTERNAL_ERR_CODE FLOWNAME  
   1 ---------- ------------- ----------------- -----------------------------------
   2 2001       -2            100               refillVoucherless                  
   1 2001       -2            320001            deactivateBBService   
   .  ..... .......... ...

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK printing

Hello, I am trying to write a formatted report into a file using .ksh script and awk. Here is the command I am trying to run echo "before awk" ${SRC_SCHEMA} echo | awk '{printf "%-20s", ${SRC_SCHEMA} }' >>$REPORT_SQL_NAME I get the following error before awk ADW awk: 0602-562 Field $()... (1 Reply)
Discussion started by: fastgoon
1 Replies

2. Shell Programming and Scripting

Printing outputs using awk.

I have a output of a command like this. the command is : bdf|sed '/^e/d'|awk '{print$2/1048576}' output : 0 0.515625 0.481979 2 2 2 7.8125 4 2 0.488281 7.8125 3.90625 4 1.95312 1 0.488281 (4 Replies)
Discussion started by: Krrishv
4 Replies

3. Shell Programming and Scripting

AWK Printing

i have a file and i want to print the second variable and add qoutes to it i do awk -F"|" '{print $2}' star.unl. i get the output xxxxxxx but i need the variable($2) to be in quotes.like "xxxxxxx" how do i do there please (3 Replies)
Discussion started by: tomjones
3 Replies

4. Shell Programming and Scripting

AWK printing

i have a file containing a line 123456 is it possible to use AWK to print it out to look like 1 2 3 4 5 6 (8 Replies)
Discussion started by: tomjones
8 Replies

5. Shell Programming and Scripting

How to store multiple outputs from an awk command?

x=`echo $line | awk -F "|" '{print $1;print NR}'` How will I get the 2 return values ($1 and NR) from awk to variables? (4 Replies)
Discussion started by: tene
4 Replies

6. Shell Programming and Scripting

create outputs from other command outputs

hi friends, The code: i=1 while do filename=`/usr/bin/ls -l| awk '{ print $9}'` echo $filename>>summary.csv #Gives the name of the file stored at column 9 count=`wc -l $filename | awk '{print $1}'` echo $count>>summary.csv #Gives just the count of lines of file "filename" i=`expr... (1 Reply)
Discussion started by: rajsharma
1 Replies

7. Shell Programming and Scripting

Awk printing help

Hallo, i have a file which looks like this: $1 $2 $3 Student1 55 Pass 55 Pass 35 Fail Student2 55 Pass 55 Pass 35 Fail i want that the $1 field... (3 Replies)
Discussion started by: saint2006
3 Replies

8. Shell Programming and Scripting

Array in awk outputs multiple values

Disclaimer: OP is 100% Awk beginner. I use this code on ASCII files I need to report against. awk 'BEGIN { tokens = 0 tokens = 0 tokens = 0 } { for (token in tokens) { if ($1 == token){print $0; tokens++;}}} END {for (token in tokens){ if( tokens ==... (1 Reply)
Discussion started by: alan
1 Replies

9. UNIX for Dummies Questions & Answers

AWK - Different outputs *Question*

I'm having a small issue with AWK: I run this in PUTTY: awk 'BEGIN{FS=","}NR==FNR{A=$1;next}{if (A==$1) print $0}' FILE1 FILE2 And it gives me the output that I expect. I wanted to create a file.awk file that i could just run instead of typing this out all the time. But its not giving my... (1 Reply)
Discussion started by: WongSifu
1 Replies

10. Shell Programming and Scripting

awk giving different outputs each time

I have a strange issue. (awk '$3 == "nfs" { cnt++ }; END { print cnt }' /etc/fstab) This is giving different count each time. To test this, tried the one here -bash-3.2$ awk '/nfs/{print $2}' /etc/fstab | wc -l 151 -bash-3.2$ awk '/nfs/{print $2}' /etc/fstab | wc -l 145... (6 Replies)
Discussion started by: sureshmsi
6 Replies
SHTOOL-PATH.TMP(1)					      GNU Portable Shell Tool						SHTOOL-PATH.TMP(1)

NAME
shtool-path - GNU shtool command dealing with shell path variables SYNOPSIS
shtool path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path path] str [str ...] DESCRIPTION
This command deals with shell $PATH variables. It can find a program through one or more filenames given by one or more str arguments. It prints the absolute filesystem path to the program displayed on "stdout" plus an exit code of 0 if it was really found. OPTIONS
The following command line options are available. -s, --suppress Supress output. Useful to only test whether a program exists with the help of the return code. -r, --reverse Transform a forward path to a subdirectory into a reverse path. -d, --dirname Output the directory name of str. -b, --basename Output the base name of str. -m, --magic Enable advanced magic search for ""perl"" and ""cpp"". -p, --path path Search in path. Default is to search in $PATH. EXAMPLE
# shell script awk=`shtool path -p "${PATH}:." gawk nawk awk` perl=`shtool path -m perl` cpp=`shtool path -m cpp` revpath=`shtool path -r path/to/subdir` HISTORY
The GNU shtool path command was originally written by Ralf S. Engelschall <rse@engelschall.com> in 1998 for Apache. It was later taken over into GNU shtool. SEE ALSO
shtool(1), which(1). 18-Jul-2008 shtool 2.0.8 SHTOOL-PATH.TMP(1)
All times are GMT -4. The time now is 06:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy