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

Awk and Null Characters

Status
Not open for further replies.

gophertee

Programmer
Oct 11, 2000
27
US
Help! Ok I am a virgin Awk programmer. I am trying to have awk catch null characters but I just found out from a awk guru that Awk and EndAwk doesn't support AIX. It seems awk running on AIX does not recognize hex. This is what I am accepting as of now:

sys_call = "mv " FILENAME " /rec/saleswork/saleshold/" FILENAME ".`date '+%j%H%M%S'`";
if (/[^A-Za-z0-9 \t!@#$%^&*\(\)\"\'\/.,;:]\r/) {
system(sys_call);
exit 0;

Any help will be beneficial!!
Thanks
Terry.Reisdorf@Regiscorp.com [sig][/sig]
 
Hi gophertee,

You might try using an octal null ( \000 ).

Something like this:

if ($0 ~ /\000/) system(sys_call) ; exit

Don't know your purpose in this situation, so this
is just a guess!

Hope this helps.

[sig]<p>flogrr<br><a href=mailto:flogr@yahoo.com>flogr@yahoo.com</a><br><a href= > </a><br> [/sig]
 
Flogrr, thanks for the insight. I will give this a try. See what is happening is this. On the RS6000 there are files passing through with specified character length (i.e. a string that begins with AN should have 192). What is happening is that line after line works than all of a sudden null characters show up in the data. I will give your insert a try and see if the null's get trapped. Like I said earlier, awk running on AIX doesn't recognize hex. Thanks for your or anyone else's help!! I appreciate it.
This is the awk script I am running:

BEGIN {
getline rec_in_1 < &quot;/usr/acct/acmmgr/EXTRMT.IN&quot;;
getline rec_in_2 < &quot;/usr/acct/acmmgr/EXTRMT.IN&quot;;
getline rec_in_3 < &quot;/usr/acct/acmmgr/EXTRMT.IN&quot;;
getline rec_in_4 < &quot;/usr/acct/acmmgr/EXTRMT.IN&quot;;
getline rec_in_5 < &quot;/usr/acct/acmmgr/EXTRMT.IN&quot;;
getline rec_in_6 < &quot;/usr/acct/acmmgr/EXTRMT.IN&quot;;
getline rec_in_7 < &quot;/usr/acct/acmmgr/EXTRMT.IN&quot;;
getline rec_in_8 < &quot;/usr/acct/acmmgr/EXTRMT.IN&quot;;
getline rec_in_9 < &quot;/usr/acct/acmmgr/EXTRMT.IN&quot;;
getline rec_in_10 < &quot;/usr/acct/acmmgr/EXTRMT.IN&quot;;
rec_type_7 = substr(rec_in_7, 24, 2);
rec_type_8 = substr(rec_in_8, 24, 2);
rec_type_9 = substr(rec_in_9, 24, 2);
rec_type_10 = substr(rec_in_10, 24, 2);
rec_len7 = substr(rec_in_7, 46, 3);
rec_len8 = substr(rec_in_8, 46, 3);
rec_len9 = substr(rec_in_9, 46, 3);
rec_len10 = substr(rec_in_10, 46, 3);
close(&quot;/usr/acct/acmmgr/EXTRMT.IN&quot;);
}
{
sys_call = &quot;mv &quot; FILENAME &quot; /rec/saleswork/saleshold/&quot; FILENAME &quot;.`date '+%j%H%M%S'`&quot;;
if (/[^A-Za-z0-9 \t!@#$%^&*\(\)\&quot;\'\/.,;:]\r/) {
system(sys_call);
exit 0;
}

if (substr($0,1,2) == rec_type_7) {
if (length($0) != (rec_len7 - 1)) {
system(sys_call);
exit 0;
}
}
if (substr($0,1,2) == rec_type_8) {
if (length($0) != rec_len8 - 1) {
system(sys_call);
exit 0;
}
}
if (substr($0,1,2) == rec_type_9) {
if (length($0) != rec_len9 - 1) {
system(sys_call);
exit 0;
}
}
if (substr($0,1,2) == rec_type_10) {
if (length($0) != rec_len10 - 1) {
system(sys_call);
exit 0;
}
}
} [sig][/sig]
 
gophertee-

If you are just wanting to get rid of the nulls, you
can sub them out on the fly and process the data in one
pass through the input file. I don't understand why you
seem to be renaming the input file in your code when your
if tests are true.

If you sub out the nulls and set $0 to the result,
you can then go ahead and manipulate the data as you will
unless the awk on your machine does not have the sub and
gsub functions. In that case, download gawk binary from
the GNU site so that you have all the functionality you
need, then, do this:

gsub(/\000/,&quot;&quot;) # all nulls in each line
$0=$0 # resets fields if necessary

.... processing code goes here .....


Good luck!

[sig]<p>flogrr<br><a href=mailto:flogr@yahoo.com>flogr@yahoo.com</a><br><a href= > </a><br> [/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top