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!

field delimeters

Status
Not open for further replies.

fumang

Technical User
May 14, 2002
7
US
I am creating a script in which I need to verify the contents of two separate documents at the same time. Say Doc. A&B. I need to go into each of these documents and verify that there is a specified number of fields, in this case 9 fields. I also need to verify that the field delimeters/separators are the same, i.e. a semi-colon. I would appreciate any help. I have been working on this for a long time and I haven't been able to make it work.

Thanks
 
hi,
why can't you just do a cmp? are there issues like....

1;2;3;4;5;6;7;8;9

is supposed to be identical to

1; 2; 3; 4; 5; 6; 7; 8; 9

what about trailing spaces

1 ;2 ;3 ;4 ;5 ;6 ;7 ;8 ;9

what about both?

1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9

is it possible to have the delimiter as part of a string in one of the files like....

1 ; 2 ; 3 ; 4 ; 5 ; 6 ; '7;junk' ; 8 ; 9




 
You could use awk to count fields in each doc and then compare in the script ...

DOC1NF=$(awk -F";" 'NR==1 {print NF}' document1)
DOC2NF=$(awk -F";" 'NR==1 {print NF}' document2)

if [ $DOC1NF = $DOC2NF ]
then
same # fields in each
else
different # of fields
fi

If the field separator is OK, then the # fields should be OK.

Greg.
 
Thanks! I played around with the awk script and got it to work. thanks for pointing me in the right direction
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top