ASCII FILE

ASCII FILE

Post by Farouk Kadr » Fri, 16 Jan 1998 04:00:00



Hi, there
Can anybody tell me how can I read an ascii file character by character
using Korn shell or AWK.
any help welcom

 
 
 

ASCII FILE

Post by Atul Bhingard » Fri, 16 Jan 1998 04:00:00


Hi Farouk,

You can separate each character in a file by using awk or nawk as follows

nawk '{ for(char=1;char<length($0);char++) \
             print substring($0,char,char+1)}' inputfile

Atul Bhingarde


>Hi, there
>Can anybody tell me how can I read an ascii file character by character
>using Korn shell or AWK.
>any help welcom


 
 
 

ASCII FILE

Post by Atul Bhingard » Fri, 16 Jan 1998 04:00:00


Hi Farouk,

Yes you can do that as follows.

nawk -F"|" '{ for(i=1;i<NF; i++) \

printf("%s,",substring($i,index($i,"=")+1,length($0)))}' inputfile

You will have to add a if statement to add carrieage return after last field
instead of a ",",

Hope it satisfies

Regards

Atul


>Hi, there
>Can anybody tell me how can I read an ascii file character by character
>using Korn shell or AWK.
>any help welcom

 
 
 

ASCII FILE

Post by Atul Bhingard » Fri, 16 Jan 1998 04:00:00


Hi Farouk,

Yes you can do that as follows.

nawk -F"|" '{ for(i=1;i<NF; i++) \

printf("%s,",substring($i,index($i,"=")+1,length($0)))}' inputfile

You will have to add a if statement to add carrieage return after last field
instead of a ",",

Hope it satisfies

Regards

Atul


>Hi, there
>Can anybody tell me how can I read an ascii file character by character
>using Korn shell or AWK.
>any help welcom

 
 
 

ASCII FILE

Post by Atul Bhingard » Tue, 20 Jan 1998 04:00:00


Hi Farouk,

Mostly some line in your file is longer than the awk capacity

Alternatively you can use fold command to wrap the file ( or lines ?? )

you can see the excat syntaxt of fole using man.

Basically fold folds each line into many lines with maximum length specified

I remember fold has syntax like "fold -c40"

fold -c50 input_file | nawk `{   ......  }`

Get back to me if you have any further questions on this matter.

Atul

>Hi, Atul
>thank you for your help, but still got another problem. Using this script
>give me an error message (record has too many fields)
>BEGIN {"|"} { for (......) {printf (substr($i.....}
>any help will be most appreciate

>Hi, there
>Can anybody tell me how can I read an ascii file character by character
>using Korn shell or AWK.
>any help welcom