Combine Both Output from the awk Script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Combine Both Output from the awk Script
# 8  
Old 04-27-2016
OK. You have shown us one output file. You have shown us one (unnamed) input file. You have shown us one script that processes three input files that we have not seen. And, if the unnamed input file is one of those three input files, it produces the output:
Code:
file01.txt:
file02.txt:
file03.txt:

So, with all of this information, the best I can do is to say that the following script produces the output you say you want:
Code:
cat <<"EOF"
file01.txt,file02.txt,file03.txt
AUE_CHMOD
AUE_CHOWN
AUE_CHROOT
AUE_CONNECT
AUE_ACCEPT
AUE_FCHOWN
AUE_FCHMOD
AUE_SETREUID
AUE_SETREGID
AUE_FCHROOT
AUE_PFEXEC
AUE_SETUID
AUE_NICE
AUE_SETGID
AUE_PRIOCNTLSYS
AUE_SETEGID
AUE_SETEUID
AUE_LCHOWN
AUE_SOCKACCEPT
AUE_SOCKCONNECT
AUE_ACLSET
AUE_FACLSET
AUE_FCHOWNAT
AUE_SETPPRIV
AUE_SETSID
AUE_SETPGID
AUE_inetd_connect
EOF

This, of course, bears no relationship to the script you showed us. That is because the output you say you want does not seem to be related in any way, shape, or form to the output you say you want from the single sample input file you have shown us.

We all seem to be wasting our time here. This will be my last post to this thread.
# 9  
Old 04-27-2016
try something like:
Code:
awk '
! fn[FILENAME]++ {f[fc++]=FILENAME}
{f[FILENAME]=FILENAME; a[$0]=$0; l[FILENAME SUBSEP $0]=$0}
END {
   print "common: " f[0], f[1] , f[2]
   for (i in a) if (l[f[0] SUBSEP i] && l[f[1] SUBSEP i] && l[f[2] SUBSEP i]) print i
   for (i in l) {
      split(i, b, SUBSEP)
      if (! (l[f[0] SUBSEP b[2]] && l[f[1] SUBSEP b[2]])) {d01[b[2]]=b[2]; df01=1}
      if (! (l[f[0] SUBSEP b[2]] && l[f[2] SUBSEP b[2]])) {d02[b[2]]=b[2]; df02=1}
      if (! (l[f[1] SUBSEP b[2]] && l[f[2] SUBSEP b[2]])) {d12[b[2]]=b[2]; df12=1}
   }
   if (df01) { print "\nuncommon: " f[0], f[1] ; for (i in d01) print i}
   if (df02) { print "\nuncommon: " f[0], f[2] ; for (i in d02) print i}
   if (df12) { print "\nuncommon: " f[1], f[2] ; for (i in d12) print i}
}' file01.txt file02.txt file03.txt


Last edited by rdrtx1; 08-31-2016 at 06:25 PM..
This User Gave Thanks to rdrtx1 For This Post:
# 10  
Old 04-28-2016
A different approach:
Code:
awk '
/:/{
  sub(/:/,x)
  f=$1
  next
} 
{
  A[$1]=A[$1] (A[$1]?",":x) f
} 
END {
  for(i in A) 
    B[A[i]]=B[A[i]] RS i
  for(j in B)
    print j ":" B[j]
}
' file

With given input sample, the output is:
Code:
file01.txt,file02.txt,file03.txt:
AUE_SETPGID
AUE_SETEUID
AUE_FCHROOT
AUE_SETGID
AUE_CHOWN
AUE_SETUID
AUE_ACCEPT
AUE_FCHMOD
AUE_CHROOT
AUE_SOCKCONNECT
AUE_SETPPRIV
AUE_PRIOCNTLSYS
AUE_SETREGID
AUE_PFEXEC
AUE_SETREUID
AUE_SOCKACCEPT
AUE_CHMOD
AUE_FACLSET
AUE_SETSID
AUE_FCHOWNAT
AUE_FCHOWN
AUE_ACLSET
AUE_LCHOWN
AUE_NICE
AUE_CONNECT
AUE_inetd_connect
AUE_SETEGID

--
With this test input:
Code:
file01.txt:
AUE_CHMOD
AUE_CHOWN
AUE_CHROOT
AUE_ACCEPT
AUE_foobar
file02.txt:
AUE_CHMOD
AUE_CHOWN
AUE_CHROOT
AUE_CONNECT
AUE_ACCEPT
AUE_inetd_connect
file03.txt:
AUE_CHMOD
AUE_CHOWN
AUE_CHROOT
AUE_CONNECT
AUE_ACCEPT

The output becomes:
Code:
file01.txt:
AUE_foobar
file02.txt,file03.txt:
AUE_CONNECT
file01.txt,file02.txt,file03.txt:
AUE_CHOWN
AUE_ACCEPT
AUE_CHROOT
AUE_CHMOD
file02.txt:
AUE_inetd_connect


Last edited by Scrutinizer; 04-29-2016 at 02:16 AM..
This User Gave Thanks to Scrutinizer For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. UNIX for Beginners Questions & Answers

awk Script Output Help

My code is listed below, I'm trying to figure out what the problem is and what I can do to fix it. The output i'm getting is: Name Low High Average 0 0 0.00 The correct output I want is the name of the Assignment, the lowest score and highest score obtained, and the Average Score... (10 Replies)
Discussion started by: Marquez3105
10 Replies

3. Shell Programming and Scripting

Pipe or combine output of three awk commands

What is the correct syntax to pipe or run three awk commands? Basically, using the output of the first awk as input in the second. Then using the output of the second awk in the third. Thank you :). awk 'FNR==NR {E; next }$3 in E {print $3, $5}' panel_genes.txt RefSeqGene.txt > update.txt |... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. UNIX for Dummies Questions & Answers

How to combine and insert missing consecutive numbers - awk or script?

Hi all, I have two (2) sets of files that are based on some snapshots of database that I want to merge and insert any missing sequential number. Below are example representation of these files: file1: DATE TIME COL1 COL2 COL3 COL4 ID 01/10/2013 0800 100 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

5. Shell Programming and Scripting

How to combine awk and bash commands in script ?

Dear friends, I am just trying write one script using 2 files one file will contain details like below #X SERVER X LOCATION URL="http://www.abcd.com" FILENAME="abc.txt" ID_NAME="myabc_xyz" SERVER_PATH="/usr/local/dummy/html/....." #Y SERVER Y LOCATION URL="http://www.xyz.com"... (10 Replies)
Discussion started by: Akshay Hegde
10 Replies

6. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

7. Shell Programming and Scripting

How to combine 2 files and output the unique & difference?

Hi Guys, I have two input files and I want to combine them and get the unique values and differences and put them into one file. See below desired output file. Inputfile1: 1111111 2222222 3333333 7860068 7860069 7860071 7860072 Inputfile2: 4444444 (4 Replies)
Discussion started by: pinpe
4 Replies

8. Shell Programming and Scripting

Combine output on same line

I am trying to get some data from a file and print it on the same line. I have a script that gets the date/time and calculates a DB query call time and sends to a file. I need to take this file and send it in a xcel like format with multiple data columns. example output file (fndbq.out) ... (3 Replies)
Discussion started by: theninja
3 Replies

9. Shell Programming and Scripting

Combine Two Commands Output

How i can combine output of two commands in one file.......i tried this but it is not working although each command is working good seperately..... head -1 filename | tail -1 filename i think there is problem with command concatenator? (16 Replies)
Discussion started by: 33junaid
16 Replies

10. Shell Programming and Scripting

script the output with awk

Please i need your help. i made this script with awk, this scripts count and list a pattern for each directory in the output as shown. but not as desired. i want the output will be listed in a tabular way, using awk: cuenta_cdrs() { for dir in * do cd $dir for file in * do ... (4 Replies)
Discussion started by: alexcol
4 Replies
Login or Register to Ask a Question