Multiple awk commands with some formatting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple awk commands with some formatting
# 1  
Old 03-23-2011
Multiple awk commands with some formatting

Hi,

I am trying to extract data from output files.
I have three awk commands that can be used. All the three commands works separately. The second and third are similar as it outputs 'line 3' and 'line 13' after
the common 'string' (I do not know how to combine them). I would like to get the output in two formats (format one and two) and I have two issues:

Issue (1) Each awk command gives me 20 lines of output.
Code:
awk '/ test-file*/{print;m=0}' out1.log > out1a.txt
awk '/ test-string/{m=1;c=0}m&&++c==3{print  $2  "  "  $3   "  "  $4  ;m=0}' out1.log > out1b.txt
awk '/ test-string/{m=1;c=0}m&&++c==13{print  $2  "  "  $3   "  "  $4  ;m=0}' out1.log > out1c.txt

Eg of outputs.

(out1a.txt)
Code:
Name1
Name2
Name3
Name4
Name5
.
.
Name20

(out1b.txt)
Code:
0.302   0.305   0.205
1.202   0.205   0.104
0.502   0.225   0.225
.
.
0.802   0.445   0.105

(out1c.txt)
Code:
0.402   0.505   0.105
1.402   0.505   0.404 
0.502   0.225   0.525 
.
.
0.902   0.945   0.605

Output One (required as):
Code:
Name1 (line 1 of out1a.txt)
0.302   0.305   0.205 (line 1 of out1b.txt)
0.402   0.505   0.105 (line 1 of out1c.txt)
Name2 (line 2 of out1a.txt)
1.202   0.205   0.104 (line 2 of out1b.txt)
1.402   0.505   0.404 (line 2 of out1c.txt)
.
.
Name20 (line 20 of out1a.txt)
0.802   0.445   0.105 (line 20 of out1b.txt)
0.902   0.945   0.605 (line 20 of out1c.txt)

Output Two (required as):
Code:
Name1         0.302            0.305            0.205
                (c1 line1 of out1b.txt)      (c2 line1 of out1b.txt)    (c3 line1 of out1b.txt)
Name1         0.302            0.505             0.105
                   (c1 line1 of out1c.txt)      (c2 line1 of out1c.txt)    (c3 line1 of out1c.txt)
Name2         1.202            0.205            0.104
                   (c1 line2 of out1b.txt)      (c2 line2 of out1b.txt)    (c3 line2 of out1b.txt)
Name2         1.402            0.505            0.404
                      (c1 line2 of out1c.txt)      (c2 line2 of out1c.txt)    (c3 line2 of out1c.txt)
.
.
.
Name20        0.802            0.445            0.105
                    (c1 line20 of out1b.txt)     (c2 line20 of out1b.txt)   (c3 line20 of out1b.txt)
Name20        0.902            0.945            0.605
                    (c1 line20 of out1c.txt)     (c2 line20 of out1c.txt)   (c3 line20 of out1c.txt)

Issue (2) If I need to extract the data from a series of files, say out2.log, out3.log ..., how can that be done?

Your help is greatly appreciated. Smilie

Last edited by Scott; 03-23-2011 at 06:32 PM.. Reason: Please use code tags
# 2  
Old 03-23-2011
For the first format try this:
Code:
paste -d '\n' out1a.txt out1b.txt out1c.txt

For the second format try:
Code:
paste -d '\n' <(paste out1a.txt out1b.txt) <(paste out1a.txt out1c.txt)

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 03-23-2011
Quote:
Originally Posted by bartus11
For the first format try this:
Code:
paste -d '\n' out1a.txt out1b.txt out1c.txt

For the second format try:
Code:
paste -d '\n' <(paste out1a.txt out1b.txt) <(paste out1a.txt out1c.txt)

The first one works, thank you Bartus.Smilie The second one says
"Missing name for redirect", though I gave a name. Smilie

Any thought on running multiple awks together and/or on (issue 2), how to extract the data from a series of files? Thanks!!
# 4  
Old 03-23-2011
Try running that second piece of code in bash or ksh shell (you are using csh, aren't you? Smilie)
# 5  
Old 03-23-2011
Quote:
Originally Posted by bartus11
Try running that second piece of code in bash or ksh shell (you are using csh, aren't you? Smilie)
You are correct. I was running in csh. Thanks for correcting me. Smilie The second code also worked. Thank you so much. Can you briefly elaborate what the code means, if you have time. Thanks.. Any suggestions on issue 2?Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issues formatting output of two commands in a single line.

I wish to generate output of two commands in the same line separated by a single white-space. Below is my command and output in the same line. ls -ltr fname1.out | awk '{$2=$4=$5=x; print}' | tr '\n' '\t' | tr -s ' '; cksum<fname1.out | cut -d' ' -f1 Output: -rw-r--r--. root Aug 26 16:57... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. UNIX for Advanced & Expert Users

Pass Multiple Commands and Open Multiple Xterms via PSS

Hello, I'm attempting to open multiple xterms and run a command as an SAP user via sudo using PSSH. So far, I'm able to run PSSH to a file of servers with no check for keys, open every xterm in to the servers in the file list, and SUDO to the SAP(ADM) user, but it won't do anything else... (11 Replies)
Discussion started by: icemanj
11 Replies

3. Shell Programming and Scripting

Combine multiple awk commands

Hi Team, I am getting input like below $ ps -ef | grep pmon | grep -v asm | grep -v grep oracle 3246 1 0 00:03 ? 00:00:01 ora_pmon_racora1 oracle 4367 1 0 00:03 ? 00:00:01 ora_pmon_test1 oracle 6893 1 0 00:03 ? 00:00:01 ora_pmon_gipora1... (6 Replies)
Discussion started by: kamauv234
6 Replies

4. Shell Programming and Scripting

Get multiple values from an xml file using one of the following commands or together awk/perl/script

Hello, I have a requirement to extract the value from multiple xml node and print out the values to new file to compare. Would be done using either awk/perl or some unix script. For example sample input file: ..... ..... <factories xmi:type="resources.jdbc:DataSource"... (2 Replies)
Discussion started by: slbmind
2 Replies

5. Shell Programming and Scripting

Variables into SED or AWK and multiple commands

Hello I am hoping you may help. I am not sure how to go about this exactly, I know the tools but not sure how to make them work together. I have two SED commands that I would like to run in a shell script. I would like to take the manual input of a user (types in when prompted) to be used... (4 Replies)
Discussion started by: lostincashe
4 Replies

6. UNIX for Dummies Questions & Answers

Explain perl formatting commands

Could you please tell the meaning of Below mentioned perl script lines: format OWNER_TOTAL = @< Owner Code @<<<<<<total: @#######.## @#######.## @#######.## @#######.## @#######.## @#######.## @#######.## @#######.## @#######.## @#######.## @###### #.## $prev_cust_type, $prev_owner_code,... (2 Replies)
Discussion started by: vinothrajan55
2 Replies

7. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

8. UNIX for Dummies Questions & Answers

Formatting Multiple fields on 1 line to multiple rows

I'm trying extract a number of filename fields from a log file and copy them out as separate rows in a text file so i can load them into a table. I'm able to get the filenames but the all appear on one line. I tried using the cut command with the -d (delimiter) option but cant seem to make it... (1 Reply)
Discussion started by: Sinbad-66
1 Replies

9. Solaris

Help with executing multiple remote commands after multiple hops

Hi SSHers, I have embedded this below code in my shell script.. /usr/bin/ssh -t $USER@$SERVER1 /usr/bin/ssh $USER2@S$SERVER2 echo uptime:`/opt/OV/bin/snmpget -r 0 -t 60 $nodeName system.3.0 | cut -d: -f3-5` SSH to both these servers are public-key authenticated, so things run... (13 Replies)
Discussion started by: LinuxUser2008
13 Replies

10. Shell Programming and Scripting

How do we use multiple commands with AWK

Hi, I have a scenario where in, I have a file named abc.txt. I extract the file names from it using. awk '/dbf$/{print $NF}' abc.txt /u01/oradata/omc/systab/omcdef.dbf /u01/oradata/omc/oratemp/temptab1.dbf Now I need to further enhance this command and also extract the mount point... (3 Replies)
Discussion started by: geetap
3 Replies
Login or Register to Ask a Question