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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Record Separating 3

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
I have a document that looks like this:

Code:
CLASS windows_mls *NULL* 0 500000 0 *NULL*
INFO 13 0 0 0 *NULL* 0 0 1 1 0 0 0 0 0 0 0 0 0 1115911974 1BA88D601DD211B2B11E00306E06A3D4
CLASS windows_mls2 *NULL* 0 500000 0 *NUL*
INFO 13 0 0 0 *NULL* 0 0 1 0 0 0 0 0 0 0 0 0 0 1115911974 1BA88D601DD211B2B11E00306E06A3D4
CLASS windows_phant *NULL* 0 500000 0 *NULL*
INFO 13 0 0 0 *NULL* 0 0 3 1 0 0 0 0 0 0 0 0 0 1107878302 42408BF81DD211B2A98600306EF463F7
CLASS windows_serv *NULL* 0 500000 0 *NULL*
INFO 13 0 0 0 *NULL* 0 0 3 0 0 0 0 0 0 0 0 0 0 1107874552 86DFF09A1DD211B299BF00306EF463F7
CLASS windows_servers_1236407 *NULL* 0 500000 0 *NULL*
INFO 13 0 0 0 *NULL* 0 0 3 0 0 1 0 0 0 0 0 0 0 1107874552 86DFF09A1DD211B299BF00306EF463F7

Every two lines is a record ..

Code:
CLASS windows_mlinks *NULL* 0 500000 0 *NULL*
INFO 13 0 0 0 *NULL* 0 0 1 0 0 0 0 0 0 0 0 0 0 1115911974 1BA88D601DD211B2B11E00306E06A3D4

I don't know how to specify that every other line begins a new record. In the example above the word "CLASS" begins each record.

I ultimately am trying to get the 2nd field on the "CLASS" line and the 10th field on the "INFO" line. I can probably figure that part out .. I just need to know how to separate the records.

Thanks


p.s. Just to verify .. Is it true that I can't specify the record separator on the command line.. for example

Code:
cat something.txt | awk -F = "\n" ; -RS = "" ...
 
Hi

Kipnep70 said:
In the example above the word "CLASS" begins each record.
Then you can use the string "CLASS" as record separator, just note that this way before the first separator will be no valid data and you have to put back the chopped "CLASS" word to the begin of the records.
Code:
awk 'BEGIN{RS="CLASS"}NR==1{next}{$0="CLASS"FS$0}1' /input/file
Kipnep70 said:
I ultimately am trying to get the 2nd field on the "CLASS" line and the 10th field on the "INFO" line. I can probably figure that part out .. I just need to know how to separate the records.
If this is your goal, then is easier to treat the two lines as two records.
Code:
awk '$1=="CODE"{print$2}$1=="INFO"{print$10}' /input/file
Kipnep70 said:
Just to verify .. Is it true that I can't specify the record separator on the command line..
Sad, but right. You can not.

Feherke.
 
yes, you can:
Code:
nawk -v RS="foo" '.....' myFile.txt

the thing is though that (if you're on Solaris) Solaris' 'nawk' only allows SINGLE characters as RS.
Bummer, but true.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
One last question, with your help my output is now:

Code:
S_Windows_Prod
0
S_Windows_Test
0
DA_Web
1
lt_Duplication
0
lt_Ejct
0
WAWG_Web
1

Can anybody suggest to me what would be the best method to use to sort my results by the value underneath each name?

Everybody with a "1" underneath goes here ---> group1.txt

Everybody with a "0" underneath goes here ----> group2.txt

Can awk do this or is there a better program?

Thanks again for your help and responses.

-Kip
 
awk '
/^CLASS /{c=$2}
/^INFO/{i=$10;print c"\n"i>"group"(2-i)".txt"}
' /input/file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Can you explain what is happening, thanks.

awk '
/^CLASS /{c=$2}
/^INFO/{i=$10;print c"\n"i>"group"(2-i)".txt"}
' /input/file
 
What did you not understand ?
awk '
/^CLASS /{
# store 2nd field on the "CLASS" line in c
c=$2
}
/^INFO/{
# store 10th field on the "INFO" line in i
i=$10
# print the 2 stored values in a file depending of the value of i:
# if i=1 then (2-i)=1, if i=0 then (2-i)=2
print c"\n"i>"group"(2-i)".txt"
}
' /input/file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top