AWK script to parse a data in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK script to parse a data in a file
# 1  
Old 07-20-2012
AWK script to parse a data in a file

Hi Unix gurus..

I have a file which has below data, It has several MQ Queue statistics;

Code:
QueueName= 'TEST1'
CreateDate= '2009-10-30'
CreateTime= '13.45.40'
QueueType= Predefined
QueueDefinitionType= Local
QMinDepth= 0
QMaxDepth= 0
QueueName= 'TEST2'
CreateDate= '2009-10-30'
CreateTime= '13.51.12'
QueueType= Predefined
QueueDefinitionType= Local
QMinDepth= 0
QMaxDepth= 6

My output should be as below, each queue details should be displayed in a single line delimited by space,

Code:
QueueName= 'TEST1' CreateDate= '2009-10-30' CreateTime= '13.45.40' QueueType= Predefined QueueDefinitionType= Local QMinDepth= 0 QMaxDepth= 0
QueueName= 'TEST2' CreateDate= '2009-10-30' CreateTime= '13.51.12' QueueType= Predefined QueueDefinitionType= Local QMinDepth= 0 QMaxDepth= 6

thanks in advance..

Last edited by Scott; 07-20-2012 at 05:03 AM.. Reason: Code tags
# 2  
Old 07-20-2012
Code:
awk 'BEGIN{ORS=FS}/^QueueName/{if(NR>1)$0=RS$0}1; END{print RS}' inputfile

Also have a look at paste command.

Last edited by elixir_sinari; 07-20-2012 at 04:06 AM..
# 3  
Old 07-20-2012
Code:
paste -s inputfile


Last edited by expert; 07-20-2012 at 03:51 AM.. Reason: code tags
# 4  
Old 07-20-2012
Quote:
Originally Posted by expert
Code:
paste -s inputfile

Serial merging will not work here..will generate a single line...check the OP's requirement again.
# 5  
Old 07-20-2012
Here is an alternate way:
Code:
awk '{if($0~/^QMax/)s="%s\n";else s="%s ";printf s,$0}' inputfile


Last edited by jlliagre; 07-20-2012 at 04:54 AM..
# 6  
Old 07-20-2012
Paste will work but you have to pass in the list of delimiters...
Code:
$ paste -s -d '      \n' file1
QueueName= 'TEST1' CreateDate= '2009-10-30' CreateTime= '13.45.40' QueueType= Predefined QueueDefinitionType= Local QMinDepth= 0 QMaxDepth= 0
QueueName= 'TEST2' CreateDate= '2009-10-30' CreateTime= '13.51.12' QueueType= Predefined QueueDefinitionType= Local QMinDepth= 0 QMaxDepth= 6

# 7  
Old 07-20-2012
Thanks a lot every one.. appreciate your help..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk , parse data from stacked columns

I am trying to rearrange stacked columns. Below is an excerpt of my data file: You can see there are two data columns stacked vertically. ITERATION ... (1 Reply)
Discussion started by: sav0
1 Replies

2. Shell Programming and Scripting

awk parse result that match data from file

i run command that return this result,example : gigabitethernet2/2/4:NotPresent, gigabitethernet2/1/17:UP, gigabitethernet2/1/10:UP, gigabitethernet2/1/5:UP, gigabitethernet2/1/9:UP, gigabitethernet2/1/36:DOWN, gigabitethernet2/1/33:DOWN, gigabitethernet2/1/8:UP,... (19 Replies)
Discussion started by: wanttolearn1
19 Replies

3. Shell Programming and Scripting

awk script to parse case with information in two fields of file

The below awk parser works for most data inputs, but I am having trouble with the last one. The problem is in the below rules steps 1 and 2 come from $2 (NC_000013.10:g.20763686_20763687delinsA) and steps 3 and 4 come from $1 (NM_004004.5:c.34_35delGGinsT). Parse Rules: The header is... (0 Replies)
Discussion started by: cmccabe
0 Replies

4. Shell Programming and Scripting

awk to split and parse unpredictable data

data.txt: CRITICAL: iLash: 97.00%, SqlPlus: 99.00%. Warning/critical thresholds: 95/98% I need to pull only the disknames: iLash and SqlPlus The following command will only pull iLash: echo "CRITICAL: iLash: 97.00%, SqlPlus: 99.00%. Warning/critical thresholds: 95/98%" | awk -F":"... (7 Replies)
Discussion started by: SkySmart
7 Replies

5. Shell Programming and Scripting

awk : Filter a set of data to parse header line and last field of multiple same match.

Hi Experts, I have a data with multiple entry , I want to filter PKG= & the last column "00060110" or "00088150" in the output file: ############################################################################################### PKG= P8SDB :: VGS = vgP8SOra vgP8SDB1 vgP8S001... (5 Replies)
Discussion started by: rveri
5 Replies

6. Shell Programming and Scripting

Parse config file data to script variable

I have a script with few pre defined variables. Also have a config file. Something like this. # config file # Define Oracle User MOD1_TAG=abcde MOD2_TAG=xyzabc MOD3_TAG=def I need to parse the config file and have each of the value copied to different variables. Please suggest what... (1 Reply)
Discussion started by: souryadipta
1 Replies

7. Shell Programming and Scripting

parse data between parenthesis using shell script

Hi I am using shell script and i need to parse the data between parenthesis.How do i do it using shell script. Ex: section(name). I want to extract name from the above string using shell script. (4 Replies)
Discussion started by: julie_s
4 Replies

8. Shell Programming and Scripting

parse data using sh script

Hi, I am a newbie to unix/shell scripting and i have a question on how to parse a txt file using perl in a sh script. I have a txt file that contains hundreds of lines with data like this.... X, Y, Latitude, Longitude 1, 142, -38.000000, -91.000000, 26.348 2, 142, 60.000000, -90.000000,... (2 Replies)
Discussion started by: moonbaby
2 Replies

9. Shell Programming and Scripting

Help!!! Shell script to parse data file.

I am faced with a :confused: tricky problem to parse a data file ( May not be a tricky problem to the scripting guru's ). Here is what I am faced with. I have a file with multiple rows of data and the rows are not of fixed length. "|" is used as a delimiters for individual columns and each row... (3 Replies)
Discussion started by: yajaykumar
3 Replies

10. Shell Programming and Scripting

To parse through the file and print output using awk or sed script

suppose if u have a file like that Hen ABCCSGSGSGJJJJK 15 Cock ABCCSGGGSGIJJJL 15 * * * * * * : * * * . * * * : Hen CFCDFCSDFCDERTF 30 Cock CHCDFCSDHCDEGFI 30 * . * * * * * * * : * * :* : : . The output shud be where there is : and . It shud... (4 Replies)
Discussion started by: cdfd123
4 Replies
Login or Register to Ask a Question