awk to split and parse unpredictable data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to split and parse unpredictable data
# 1  
Old 11-04-2013
awk to split and parse unpredictable data

data.txt:

Code:
CRITICAL: iLash: 97.00%, SqlPlus: 99.00%. Warning/critical thresholds: 95/98%

I need to pull only the disknames:
Code:
iLash and SqlPlus

The following command will only pull iLash:

Code:
echo "CRITICAL: iLash: 97.00%, SqlPlus: 99.00%. Warning/critical thresholds: 95/98%" | awk -F":" '{print $2}' | sed 's~ ~~g'

the data in data.txt is unpredictable. in this particular data which i posted, there's only two disk names alerting.

sometimes there will be more or less. i need help with an awk command that will only spit out the disk names.
# 2  
Old 11-04-2013
Like this ?
Code:
echo "CRITICAL: iLash: 97.00%, SqlPlus: 99.00%. Warning/critical thresholds: 95/98%" | awk -F'[ :,]' ' { print $3,$7} '

output:
Code:
iLash SqlPlus


Last edited by greet_sed; 11-04-2013 at 11:02 AM.. Reason: Add output
This User Gave Thanks to greet_sed For This Post:
# 3  
Old 11-04-2013
How then to know when a valid disk name is present?
I am thinking to look immediately prior to
Code:
: xx.xx%

This User Gave Thanks to joeyg For This Post:
# 4  
Old 11-04-2013
doesn't seem be working. it's only grabbing the number of columns it is told to grab.
Code:
echo "CRITICAL: iDash: 97.00%, iGash: 97.00%, iTash: 97.00%, SQLPlus: 99.00%. Warning/critical thresholds: 95/98%" | awk -F'[ :,]' ' { print $3,$7} '

output:
Code:
iDash iGash

# 5  
Old 11-04-2013
Quote:
Originally Posted by SkySmart
doesn't seem be working. it's only grabbing the number of columns it is told to grab.
Code:
echo "CRITICAL: iDash: 97.00%, iGash: 97.00%, iTash: 97.00%, SQLPlus: 99.00%. Warning/critical thresholds: 95/98%" | awk -F'[ :,]' ' { print $3,$7} '

output:
Code:
iDash iGash

Why don't you show more data ? what greet_sed posted works fine for given data
# 6  
Old 11-04-2013
For your data in post#4, try
Code:
echo "CRITICAL: iDash: 97.00%, iGash: 97.00%, iTash: 97.00%, SQLPlus: 99.00%. Warning/critical thresholds: 95/98%" | sed -r 's/^[^:]*:|\. .*$|: [0-9.]*%//g'
 iDash, iGash, iTash, SQLPlus

# 7  
Old 11-04-2013
I am not sure that what you expect really... for given input in #1 and #4 this will work

Code:
$ awk 'gsub("CRITICAL|[0-9.:%  ]|Warning.*",x)' file

for input in #1
Code:
$ echo "CRITICAL: iLash: 97.00%, SqlPlus: 99.00%.  Warning/critical thresholds: 95/98%" | awk 'gsub("CRITICAL|[0-9.:%  ]|Warning.*",x)'
iLash,SqlPlus

for input in #4
Code:
$ echo "CRITICAL: iDash: 97.00%, iGash: 97.00%, iTash: 97.00%, SQLPlus: 99.00%. Warning/critical thresholds: 95/98%" | awk 'gsub("CRITICAL|[0-9.:% ]|Warning.*",x)'
iDash,iGash,iTash,SQLPlus

This User Gave Thanks to Akshay Hegde For This Post:
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 - split data based on the count

Greetings Experts, I am generating a validation query through awk and facing an issue, which I need to overcome by splitting the data based on the pattern matching count in the value of an array. File1 -- Table11@column1@date@Table21@column1@varchar(10)@d;... (4 Replies)
Discussion started by: chill3chee
4 Replies

3. 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

4. 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

5. Shell Programming and Scripting

AWK script to split data and find average

Input: 2.58359023380340e+02 1.43758864405595e+02 -7.65700666212508e+00 1.06460208083228e+02 1.26185441783936e+02 -3.41389169427027e+01 -1.40393299309592e+02 -3.07758776849508e+01 1.45067703495838e+02 1.79405834959073e+02 5.06666234594205e+01 OUT 2.0105894389e+02 (average of... (8 Replies)
Discussion started by: chrisjorg
8 Replies

6. Shell Programming and Scripting

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; QueueName= 'TEST1' CreateDate= '2009-10-30' CreateTime= '13.45.40' QueueType= Predefined QueueDefinitionType= Local QMinDepth= 0 QMaxDepth= 0 QueueName= 'TEST2' CreateDate= '2009-10-30'... (6 Replies)
Discussion started by: dd_psg
6 Replies

7. Shell Programming and Scripting

awk to split one field and print the last two fields within the split part.

Hello; I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
Discussion started by: yifangt
5 Replies

8. Shell Programming and Scripting

Split File data using awk

HI Guys, I need to split the file in to number of files . file contains FILEHEADER and EOF . I have to split n number of times . I have to form the file with each splitted message between FILEHEADER and EOF using awk beign and end . how to implement please suggest. (2 Replies)
Discussion started by: manish8484
2 Replies

9. Shell Programming and Scripting

awk script to split field data

Hi Experts, I have a Input.txt document which contains data fields seperated by tabs. There are 4 fields totally Named UNIQUE, ORDER, CONTACT and WINS. The UNIQUE field contains unique ID and the CONTACT field contains data seperated by comma in some records. I am looking to write an awk script... (12 Replies)
Discussion started by: forumthreads
12 Replies

10. Shell Programming and Scripting

Shell script to parse/split input string and display the tokens

Hi, How do I parse/split lines (strings) read from a file and display the individual tokens in a shell script? Given that the length of individual lines is not constant and number of tokens in each line is also not constant. The input file could be as below: ... (3 Replies)
Discussion started by: yajaykumar
3 Replies
Login or Register to Ask a Question