Visit Our UNIX and Linux User Community


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
# 1  
Old 04-25-2016
Combine Both Output from the awk Script

Hi,

Is there anyway to combine output from the awk scripting.

Code:
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

Code:
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.

Code:
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:

Code:
file01.txt file02.txt:
[SAME CONTENT1]

file03.txt
[SAME CONTENT2]


Last edited by RudiC; 04-25-2016 at 04:48 AM.. Reason: changed quote tags to code tags
# 2  
Old 04-25-2016
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

Last edited by Scrutinizer; 04-25-2016 at 02:55 AM..
# 3  
Old 04-25-2016
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).
# 4  
Old 04-25-2016
Quote:
Originally Posted by Don Cragun
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 ----------

Quote:
Originally Posted by Scrutinizer
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
It is the content of one big file.
# 5  
Old 04-26-2016
Is there anyway to combine similar output together.
# 6  
Old 04-26-2016
Quote:
Originally Posted by alvinoo
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.
# 7  
Old 04-27-2016
Here is the desired output:
Quote:
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
 

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

Featured Tech Videos