Grep with condition


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep with condition
# 1  
Old 05-26-2013
Grep with condition

I have file input

Code:
AAAA_XX_Start> rlong . 0W

130526-11:36:13 10.128.13.226 9.0j RBS_NODE_MODEL_N_1_50 stopfile=/tmp/13019
..
=================================================================================================================
MO              licenseCapacityNum100WPowerAmplifiers licenseCapacityNum120WPowerAmplifiers licenseCapacityNum40WPowerAmplifiers licenseCapacityNum60WPowerAmplifiers licenseCapacityNum80WPowerAmplifiers licenseStateNum100WPowerAmplifiers licenseStateNum120WPowerAmplifiers licenseStateNum40WPowerAmplifiers licenseStateNum60WPowerAmplifiers licenseStateNum80WPowerAmplifiers
=================================================================================================================
NodeBFunction=1 0                                     0                                     3                                    3                                    3                                    0 (DISABLED)                       0 (DISABLED)                       1 (ENABLED)                       1 (ENABLED)                       1 (ENABLED)                      
=================================================================================================================

BBBB_XX_Start> rlong . 0W

CCCC_XX_Finish> rlong . 0W

130526-11:42:30 10.165.157.35 9.0j RBS_NODE_MODEL_N_1_50 stopfile=/tmp/18636
..
=================================================================================================================
MO              licenseCapacityNum100WPowerAmplifiers licenseCapacityNum120WPowerAmplifiers licenseCapacityNum40WPowerAmplifiers licenseCapacityNum60WPowerAmplifiers licenseCapacityNum80WPowerAmplifiers licenseStateNum100WPowerAmplifiers licenseStateNum120WPowerAmplifiers licenseStateNum40WPowerAmplifiers licenseStateNum60WPowerAmplifiers licenseStateNum80WPowerAmplifiers
=================================================================================================================
NodeBFunction=1 0                                     0                                     3                                    3                                    3                                    0 (DISABLED)                       0 (DISABLED)                       1 (ENABLED)                       1 (ENABLED)                       1 (ENABLED)                      
=================================================================================================================


DDDD_AA_Pause> rlong . 0W

130526-11:43:41 10.165.158.38 9.0j RBS_NODE_MODEL_N_1_49 stopfile=/tmp/4611
..
=================================================================================================================
MO              licenseCapacityNum100WPowerAmplifiers licenseCapacityNum120WPowerAmplifiers licenseCapacityNum40WPowerAmplifiers licenseCapacityNum60WPowerAmplifiers licenseCapacityNum80WPowerAmplifiers licenseStateNum100WPowerAmplifiers licenseStateNum120WPowerAmplifiers licenseStateNum40WPowerAmplifiers licenseStateNum60WPowerAmplifiers licenseStateNum80WPowerAmplifiers
=================================================================================================================
NodeBFunction=1 0                                     0                                     3                                    3                                    3                                    0 (DISABLED)                       0 (DISABLED)                       1 (ENABLED)                       1 (ENABLED)                       1 (ENABLED)                      
=================================================================================================================


I expect to have the output like

Code:
AAAA_XX_Start,0,0,3,3,3,0,0,1,1,1
BBBB_XX_Start,0,0,0,0,0,0,0,0,0,0
CCCC_XX_Finish,0,0,3,3,3,0,0,1,1,1
DDDD_AA_Pause,0,0,3,3,3,0,0,1,1,1

I did
Code:
nawk '/egrep -i/ { x = $1 } /NodeBFunction=1/ { print x, $2,$3,$4,$5,$6,$7,$8,$9 }' OFS="," input

i run the script above, well i still cant find what i expect

please help
# 2  
Old 05-26-2013
Your script is using the regular expression "egrep -i" but that pattern is absent from the input file, so the first action in your script will never happen. Try using a different pattern, for example /_.*>/

Last edited by Scrutinizer; 05-26-2013 at 04:11 AM..
# 3  
Old 05-26-2013
i've just seen that i have more complex variation of input

input

Code:
AAAA_XX_Start> rlong . 0W

130526-11:36:13 10.128.13.226 9.0j RBS_NODE_MODEL_N_1_50 stopfile=/tmp/13019
..
=================================================================================================================
MO              A B C D E F G H I J
=================================================================================================================
NodeBFunction=1 0 0 3 3 3 0 (DISABLED) 0 (DISABLED) 1 (ENABLED) 1 (ENABLED) 1 (ENABLED)                      
=================================================================================================================

BBBB_XX_Start> rlong . 0W

CCCC_XX_Finish> rlong . 0W

130526-11:42:30 10.165.157.35 9.0j RBS_NODE_MODEL_N_1_50 stopfile=/tmp/18636
..
=================================================================================================================
MO              A B C D E F G H I J
=================================================================================================================
NodeBFunction=1 0 0 3 3 3 0 (DISABLED) 0 (DISABLED) 1 (ENABLED) 1 (ENABLED) 1 (ENABLED)                      
=================================================================================================================


DDDD_AA_Pause> rlong . 0W

130526-11:43:41 10.165.158.38 9.0j RBS_NODE_MODEL_N_1_49 stopfile=/tmp/4611
..
=================================================================================================================
MO              A B C D E F G H I J
=================================================================================================================
NodeBFunction=1 0 0 3 3 3 0 (DISABLED) 0 (DISABLED) 1 (ENABLED) 1 (ENABLED) 1 (ENABLED)                    
=================================================================================================================

EEEE_DD_Pause> rlong . 0W

130526-14:14:52 10.133.1.152 9.0j RBS_NODE_MODEL_M_1_43 stopfile=/tmp/19117
.
=================================================================================================================
MO              C D H I
=================================================================================================================
NodeBFunction=1 3 0 1 (ENABLED) 0 (DISABLED)                     
=================================================================================================================

i expect the output below

Code:
MO,A,B,C,D,E,F,G,H,I,J
AAAA_XX_Start,0,0,3,3,3,0,0,1,1,1
BBBB_XX_Start,0,0,0,0,0,0,0,0,0,0
CCCC_XX_Finish,0,0,3,3,3,0,0,1,1,1
DDDD_AA_Pause,0,0,3,3,3,0,0,1,1,1
EEE_DD_Pause,,,3,0,,,1,0

i did correct the script

Code:
nawk '/_.*>/ { x = $1 } /NodeBFunction=1/ { print x, $2,$3,$4,$5,$6,$7,$8,$9 }' OFS="," input | tr -d ">"

but the result is

Code:
AAAA_XX_Start,0,0,3,3,3,0,(DISABLED),0
CCCC_XX_Finish,0,0,3,3,3,0,(DISABLED),0
DDDD_AA_Pause,0,0,3,3,3,0,(DISABLED),0
EEEE_DD_Pause,3,0,1,(ENABLED),0,(DISABLED),,

pls help

Last edited by radius; 05-26-2013 at 06:00 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Combining grep patterns with OR condition?!

Hello! I have a question about how to combine patterns in grep commands with the OR operator. So I have this little assignment here: Provide a regular expression that matches email addresses for San Jose City College faculty. A San Jose City college faculty’s email address takes the form:... (1 Reply)
Discussion started by: kalpcalp
1 Replies

2. UNIX for Dummies Questions & Answers

How to grep with certain condition?

hi all, i have an xml what i have to do is to search for the source id(s1) and if it matches with that in xml then extract the file mask from the name of the file i.e if the file name is idr_%YYYY%%MM%%DD%_%N%.idr then , i want the part after first % and before last % ie in this case ... (5 Replies)
Discussion started by: ramsavi
5 Replies

3. UNIX for Dummies Questions & Answers

Grep certain lines with condition

file input aaaa,52C aaaa,50C bbbb,50C bbbb,58C aaaa,52C bbbb,50C aaaa,30C bbbb,58C cccc,60C i want to print uniq lines with its max value of column2 expected output aaaa,52C bbbb,58C cccc,60C tks (4 Replies)
Discussion started by: radius
4 Replies

4. Shell Programming and Scripting

Where condition in grep or awk?

Dear All, I need help.. I am having a csv file. Home_TITLE,People_TITLE,Repo_ALIAS HMN5530,RKY5807,/mine_repo/rike001 HMN5530,SRY6443,/mine_repo/rike001 HMN5530,ARDY001,/mine_repo/rike001 If i have two value in varible RKY5807, HMN5530. how can fetch and store another value... (6 Replies)
Discussion started by: yadavricky
6 Replies

5. Shell Programming and Scripting

grep not equal to condition

I have below files under dir_a and dir_b and i want to sort out number of dir_a and dir_b files seperately and if i do the grep it should retrun 2 files in dir_a and 1 file in dir_b. /dir_a/12345678 /dir_a/87654321 /dir_a/dir_b/12345687 But i am getting cat file|grep dir_a|wc -l 3... (6 Replies)
Discussion started by: prash358
6 Replies

6. Shell Programming and Scripting

grep in the if condition

Hi, In this code can able to match the pattern without case sensitive. Is that possible? if u knw plz help me... code: echo "Enter name to search" read n if ; echo "name found" else echo "Not Found" fi (8 Replies)
Discussion started by: boopal
8 Replies

7. Shell Programming and Scripting

grep inside if condition - need help

hi i need help with below code. if ] then log "Exiting the script as ID= NULL" log "Please run script first." fi i am calling grep inside this but its not running any ideas why ?? input file is like this -- Msg 102, Level 20, State 1: Server... (4 Replies)
Discussion started by: dazdseg
4 Replies

8. Homework & Coursework Questions

Grep line above X condition

1. The problem statement, all variables and given/known data: I have to grep a data file called datebook.txt. The last information in each line is a salary. I have to grep all the lines which precede those lines with 6 figure salaries. I can't SID it, or use Perl. It has to be grep (or egrep or... (3 Replies)
Discussion started by: DrSammyD
3 Replies

9. Shell Programming and Scripting

grep command with AND condition

I want to do a grep with AND condition. I have three files. file1.txt ======== UNIX ...... WINDOWS ........ ORACLE file2.txt ======== UNIX ....... WINDOWS ...and many such files in a directory (6 Replies)
Discussion started by: prasperl
6 Replies
Login or Register to Ask a Question