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!

AWK AIX 3

Status
Not open for further replies.

malpa

Technical User
Feb 8, 2004
122
CO
First Thanks for your help.

I have a problem with my script in AIX, In LINUX I have not problem.

awk -f extraetulua.awk file.txt

file.txt contain null characters like this ^@, ^O,. The file contain a line of 2097152 characters.

Script print in another file all the characters except the null characters. When the script find a ^O, print 9 or when the script find ^@ it doesn´t print.

First problem. In AIX, I can not find the way to write in a script the null character ^@. In linux Ctrl v + Ctrl j = ^@

Second problem. the script doesn´t run in AIX, and it show me a problem with v="*". I have changed the var v some times change it for \*, /*/, "*", "'*'", but the same, it show me that there is a problem whit a var v="*"

awk: 0602-502 The statement cannot be correctly parsed. The source line is 12.
awk: 0602-521 There is a regular expression error.
?*+ not preceded by valid expression.

My script: extraetulua.awk

{
i=1
x="[0-9]"
y="[a-z]"
z=" "
w="*"
v="^O"



while (i <= 2097152){
if ( substr($0,i,1) ~ x || substr($0,i,1) ~ y || substr($0,i,1) ~ z || substr($0,i,1) ~ w }
{
printf &quot;%s&quot;,substr($0,i,1) > &quot;tmp&quot;
)
if (substr($0,i,1) ~ v)
{
printf &quot;%s&quot;,9 > &quot;tmp&quot;
}
ì++
}
}

malpa

Thanks for your Help again

























 
substr($0,i,1) == w }

Hope This Help
PH.
 
Another approch :
[tt]
awk '
{
gsub(/^@/,&quot;9&quot;); # replace ^@ by 9
gsub(/[^0-9a-z *]/,&quot;&quot;); # Remove unwanted chars
printf &quot;%s&quot;,$0; # print result (no ending NL)
}
' input_file > tmp
[tt]

Jean Pierre.
 
To get a NULL character in your script try

w = &quot;\000&quot;

For the ^O try

v = &quot;\017&quot;

I think ^O is octal 17. If I am wrong, use

od -c file > file.lst

to find out what it is.

Using gsub as suggested by aigles is probably a better approach

{
gsub(/[^0-9a-z *]/,&quot;&quot;)
gsub(&quot;\017&quot;,&quot;9&quot;)
gsub(&quot;\000&quot;,&quot;X&quot;)
printf $0
}


CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
Anyway, the fastest way to get rid of null chars:
Code:
tr -d '\00'

Hope This Help
PH.
 
Sorry, the gsub solution should be

{
gsub(&quot;\017&quot;,&quot;9&quot;)
gsub(/[^0-9a-z *]/,&quot;&quot;)
printf $0
}

(assuming you want \000 to be deleted from the file)

CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
Thanks to all for its valuable collaboration.

I test the all solutions and all worked in LINUX
thanks aigles
thanks CaKiwi
thanks PVH

, but in AIX only works tr -d '\0' or tr '\017' '9' < >.

(Thanks PVH again).


BUGS AIX with gsub
size of file cdr0001 is 2097152 bytes.

cdr0001
#####
............................................................
00222426760000^O0000025335*00201 040202203532203845000312 cal7
017000 040202
002224267600000000025335900201 040202203532203845000312 cal7
017000 040202
^@^@^@^@^@^@^@^@002224267600000000025335900201 040202203532203845000312 cal7
017000 040202
...................................................blabla...

############
test.awk
....

{
gsub(&quot;\017&quot;,&quot;9&quot;);
gsub(/[^0-9a-z *]/,&quot;&quot;);
printf &quot;%s&quot;,$0 > &quot;test.txt&quot;;
}

....

awk -f test.awk cdr0001
awk: 0602-581 The result o of the gsub function
cannot be longer than 10,239 bytes.
The input line number is 198. The file is cdr0001.
The source line number is 2.

size of file test.txt is 1191150 bytes

I do not understand which the problem in AIX


All deserve a star for your assistance.
 
Good that you got the problem solved. I agree that PHV's suggestion was the best. The problems with the other solutions on AIX seem to be caused by internal limits in the AIX version of awk. Linux uses the GNU version of awk (gawk) which is generally limited only by your system resources.

CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
The problem can be resolved using only 'tr' :

tr '\017' '9' < file.txt | tr -cd '0-9a-z *'

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top