Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help!!!!!!!!!!!!!!!

Status
Not open for further replies.

Currando

ISP
Feb 13, 2001
25
0
0
ES
Hello,

I´m new developer in awk and i need help in a program. I have a file with this estructure:

name: john@ais.net,class=Native
changetype: modify
replace: name
name: john2@ais.net
-

name elen@fly.com,class=Unix
changetype: modify
replace: password
password: 12345
-

I need find all users with a type of attribute, for example "class=Native" and get all lines until the simbol -

In the previous example the script return:

name: john@ais.net,class=Native
changetype: modify
replace: name
name: john2@ais.net
-

In a different file. Can anybody help me!!!!! :)

Sorry for my English
 

Hello, Currando!

I think, this is a problem solution:


/class=Native/ { patternFound = 1 }

patternFound == 1 { print $0 }

/^-/ { patternFound = 0 }


You can use redirection in command line.

"Verily, verily, I say unto you, he that
believeth on me hath everlasting life,"
Jesus (John 6:47).

KP.
 
Two way that I can think of...

1: /class=Native/,/^-$/ { print; }
2: BEGIN { RS = ""; } /class=Native/ { print; }

Both will eat the blank line that follows the -, if that is important, then you will need to change #2:

BEGIN { RS = ""; } /class=Native/ { print; print ""; }

Changes to #1 are left as an exercise for the student :).

-- Derek Ludwig
Derek Ludwig
derek@ludwig.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top