awk & display on one line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk & display on one line
# 1  
Old 12-22-2010
awk & display on one line

Code:
awk '/description/ || /instances/ {print;getline;print}' rtprod2.scp

This command gives me something like below.
Code:
description=OpsExec_Clinical
instances=0
description=OpsExec_Pharmacy
instances=1
description=
instances=0
description=
instances=0
description=
description=OP_MVOR_ORU_OUT
instances=0

What I want is two things:

1) if description= and instances=0, then skip them as to they are not needed.
so, only these will be skipped:
Code:
description=
instances=0
description=
instances=0
description=

2) if description=xxxx and instances=x, then I want them to be displayed as
Code:
OpsExec_Clinical [0]
OpsExec_Pharmacy [1]
OP_MVOR_ORU_OUT [0]

so that the repetitive words, description= and instances=, are removed and put the numeric in [ ], and display on one line.

Please advise.Smilie

Last edited by Scott; 12-23-2010 at 06:47 AM.. Reason: Please use code tags for terminal output and files also.
# 2  
Old 12-22-2010
Code:
awk -F= '/description=..*/ || /instances=/ {if(substr($0,1,11)=="description"){a=$2;getline;b=$2;print a" ["b"]";}}' rtprod2.scp

This User Gave Thanks to anurag.singh For This Post:
# 3  
Old 12-22-2010
That works great!

My bad on omitting an important piece of line here.
Code:
[50]
description=CPM Application Authorization
instances=4

[51]
description=CPM Script
instances=35

The same rule (if description= and instances=0, then skip them as to they are not needed) applies.

What I want is the numbers (in this case, 50 , 51) in front of each line.
Code:
[50] CPM Application Authorization <4>
[51] CPM Script <35>

I am sorry for asking this question again.

Please advise.

Last edited by Scott; 12-23-2010 at 06:48 AM.. Reason: Code tags
# 4  
Old 12-22-2010
Pls give the actual content of rtprod2.scp.. not complete file but a sample covering all kinds of records.
# 5  
Old 12-22-2010
Here is the sample.

Each block begins with [number]. So, I need the info from the first 3 lines, i.e.
Code:
[50] CPM Application Authorization <4>
[51] CPM Script <35>


[50]
description=CPM Application Authorization
instances=4
restart=Y

[50.aix-rs6000]
path=cer_exe/srv_drvr
parameters=cer_exe/cpm_srvapp

[50.prop.aix-rs6000]
Data Segment Size=268435456
DependencyGroup=1
SSC Binding=application
User Name=d_prod

[51]
description=CPM Script
instances=35
restart=Y

[51.aix-rs6000]
path=cer_exe/cpm_srvscript
parameters=-offer

[51.prop.aix-rs6000]
DependencyGroup=2
killtime=2
SSC Binding=script
User Name=d_prod

[52]
description=CPM Code Cache Manager
instances=3
restart=Y
......

Please advise.

Last edited by Scott; 12-23-2010 at 06:49 AM..
# 6  
Old 12-23-2010
Code:
awk -F= '/\[..\]/,/instances=/ {a=$1;getline;if($1=="description" && $2){b=$2;getline;print a" "b" <"$2">";}}' rtprod2.scp

# 7  
Old 12-23-2010
It works great except one thing.

If there is empty values like below:
Code:
[665]
description=
instances=0
restart=N

[665.aix-rs6000]
path=
parameters=

[665.prop.aix-rs6000]
DependencyGroup=3
User Name=d_prod

then, the next ones with values like the below are skipped.
Code:
[668]
description=OpsExec_System Management
instances=1
restart=Y

So, awk runs fine until it hits the ones like this:
Code:
[665]
description=
instances=0
restart=N

Please advise.

Moderator's Comments:
Mod Comment Please use code tags

Last edited by Scott; 12-23-2010 at 01:23 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display the file name on each line using awk

How do I display the filename that has been awk to each of the line in Unix, i need to so far I have tried {print FILENAME;nextfile} but to no avail. `awk -F, '/1.2 Install TCP Wrappers/ {P=0} /1.1 Apply latest OS patches/ {P=1} P' solarisappsummary.txt solarisdbsummary.txt` For... (6 Replies)
Discussion started by: alvinoo
6 Replies

2. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

3. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

4. Shell Programming and Scripting

Display all the matches lines in one line using awk

Please can you let me know how to print all the matching lines from a file in one single line using awk. Thanks I have the following data in the input file data1 voice2 voice1 speech1 data2 data3 ... ... voice4 speech2 data4 and the output should be as follows data1 data2... (4 Replies)
Discussion started by: Sudhakar333
4 Replies

5. Shell Programming and Scripting

awk Help: Filter Multiple Entry & print in one line.

AWK Gurus, data: srvhcm01 AZSCI srvhcm01 AZSDB srvhcm01 BZSDB srvhcm01 E2QDI31 srvhcm01 YPDCI srvhcm01 YPDDB srvhcm01 UV2FSCR srvhcm01 UV2FSBI srvhcm01 UV2FSXI srvhcm01 UV2FSUC srvhcm01 UV2FSEP srvhcm01 UV2FSRE srvhcm01 NASCI srvhcm01 NASDB srvhcm01 UV2FSSL srvhcm01 UV2FSDI (7 Replies)
Discussion started by: rveri
7 Replies

6. Shell Programming and Scripting

Using Grep & find & while read line in a script

Hello people! I would like to create one script following this stage I have one directory with 100 files File001 File002 ... File100 (This is the format of content of the 100 files) 2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0 then I have one... (0 Replies)
Discussion started by: Abv_mx81
0 Replies

7. UNIX for Dummies Questions & Answers

awk - display from line number to regex

Hi. Is there a way in awk to show all lines between a line number and the next line containing a particular regex? We can do these, of course: awk '/regex1/,/regex2/' filename awk 'FNR > X && FNR < Y' filename But can they be combined? Thanks. (3 Replies)
Discussion started by: treesloth
3 Replies

8. HP-UX

Export Display Through Telnet & Xming

HI, HP-UX B.11.00 A 9000/785 (ta) I am trying to export a display using Xming & and Telnet (not SSH) but when I try.. $ DISPLAY=192.168.1.75:0.0 $ export DISPLAY $ xclock and get.. Xlib: connection to "192.168.1.75:0.0" refused by server Xlib: No protocol specified Error:... (4 Replies)
Discussion started by: Pauly
4 Replies

9. UNIX for Dummies Questions & Answers

diff between $TERM & $DISPLAY

Can anybody pls explain me the diff between $TERM & $DISPLAY ? Thanks in advance. (1 Reply)
Discussion started by: Venky
1 Replies

10. Shell Programming and Scripting

Can't figure out how to display specific data from a line using awk.

Hello, I cannot figure this one out. I would like to do the following. I have a line that has 7 words. It is possible that the line can have 20 words too. I always want to show the 9th word and beyond. The 9th word will always change so I do not have something to search for, so I think... (1 Reply)
Discussion started by: ctcuser
1 Replies
Login or Register to Ask a Question