Combine Both Output from the awk Script

Hi,

Is there anyway to combine output from the awk scripting.

file01.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
file02.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
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
OUTPUT=4.2
END=4.3
FILELIST="file01.txt file02.txt file03.txt"

for file in $FILELIST
do
echo "$file:"
awk /"^$OUTPUT$"/,/"^$END$"/ $file | grep -v "^$OUTPUT$\|^$END$"
done

My desired output will be this if output from the awk is the same.

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

However if it is different need to split by:

file01.txt file02.txt:
[SAME CONTENT1]

file03.txt
[SAME CONTENT2]

Hi, is file01.txt: , file02.txt: etcetera part of the content of one big file, or the names of separate files ?

--
Please use code tags also for data samples

Huh?

You show us three files named file01.txt , file02.txt , and file03.txt . And you show us a script that processes three files named 2ihp-cmnwls03.txt , 2ihp-cmnwls03.txt , and 2lhp-cmndb02.txt . Assuming that the three files you will be processing have the same contents as the files this script is processing, the awk script will produce no output (since neither ERE given as addressing arguments match anything in any of the three identical input files). And the grep -v that is specified is a VERY slow way to copy the input to the grep to its output (since a grep with a BRE containing four anchors can never match any input line).

Sorry. I am renamed the required input to file01.txt file02.txt file03.txt

---------- Post updated at 01:17 AM ---------- Previous update was at 01:16 AM ----------

It is the content of one big file.

Is there anyway to combine similar output together.

Yes!

But, before we can help you do that you need to CLEARLY describe what your inputs are, what "combine similar output together" means, and show us exactly what output you hope to produce from a couple of sets of small sample input files.

Our mind reading capabilities do not seem to be nearly as good as you might have imagined.

Here is the desired output:

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:

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:

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.

try something like:

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
1 Like

A different approach:

awk '
/:/{
  sub(/:/,x)
  f=$1
  next
} 
{
  A[$1]=A[$1] (A[$1]?",":x) f
} 
END {
  for(i in A) 
    B[A]=B[A] RS i
  for(j in B)
    print j ":" B[j]
}
' file

With given input sample, the output is:

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:

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:

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
1 Like