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

shell script or awk for automated fields checking.

Status
Not open for further replies.

chz013

Programmer
Jan 5, 2003
73
0
0
US
I have a record that is like this below; records like this
are delimited by --- lines; I need to write a bash script
that automatically checks for almost all the fields
defined on each row;
1- Is it difficult to write a shell script that processes
these records and checks each field in each record ?
Do you have an example script that reads a file that
contain all these records and make checks on them ?
2 - Is it better to write an awk script over shell script
if I only need to check about 10 - 12 fields in each record ? Do you have an example script that reads a file
that contain all these records and make checks on them ?

Any comments or help is appreciated.
Advance thanks

----------------------------------------------------------
Record Checksum: 110
Record Number: 1
Reference Number: 1
Record Type: 2 => MTC

IM Field Content:
IM field: (001) => IM
EVEN/ODD bit: (1) => odd
IM Id: 316

SType: 0x00 => LS
CNumber Field Content:
L: 1
Ext: (1) => No
Tnum: (001) => No
PId: (0001) => No
D:

ONum Field Content:
L: 6
Ext: (1) => No
Tnum: (001) => No
PId: (0001) => No
D: 1234567890

TNum Field Content:
L: 6
Ext: (1) => No
Tnum: (001) => No
PId: (0001) => No
D: 0987654321

CTime: 0x0000 =>
S Du: 0
C Du: 0x1 => 1
L ID: 5
C Id: 0
Cause for T: 1 => N Re
O.t g ID: 0

Diag hex dump:
00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
----------------------------------------------------------
 
It depends a lot on what you mean by "checks each field in each record". What kind of things are you checking for?

I would definitely use awk for this in any case. Taking one of the more complex examples, to check whether the Tnum: value under the Onum: field content was set to "No", you could use:

[tt]awk '
/Field Content:/ { FIELDCONTENT=$1 }
FIELDCONTENT == "ONum" && $1 == "Tnum:" && $NF != "No" {
print "Onum:Tnum is not No, it is " $NF
}
' recordsfile[/tt]

$1 refers to the first field on the row. $NF refers to the last field on the row. By default fields are separated by white space (spaces and tabs).

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top