1.

Solve : n00b need help . . . on converting *.ASK file format?

Answer»

this is shame to tell that during college time, lecture told me to study and i skipped

my programming class.

what i need is a batch file to CONVERT following files:-

example 1:- 42 digits data.
Code: [Select]005974e21c

00175002152F416B5604FF78AD18A7EBFEA6DF897E

example 2:- 84 digits data
Code: [Select]005974e21c

00079001179ACB015460056A55ADCCEFA83FC835E40129899427274E1BF4C440EA3B11F1B016E1F80616

output format:-

Code: [Select][CERT_PROG_DATA_IN]
RAP_PUBLIC_ID=
APE_PUBLIC_ID=

For 42 digits data, first 2 digits always are "00" and to be omitted.

Output for example 1:-
Code: [Select][CERT_PROG_DATA_IN]
RAP_PUBLIC_ID=175002152F416B5604FF78AD18A7EBFEA6DF897E
APE_PUBLIC_ID=

For 84 digits data, first 2 digits always are "00" and "01" on 43th & 44TH digits to be omitted.

Output for example 2:-
Code: [Select][CERT_PROG_DATA_IN]
RAP_PUBLIC_ID=079001179ACB015460056A55ADCCEFA83FC835E4
APE_PUBLIC_ID=29899427274E1BF4C440EA3B11F1B016E1F80616

File extension is *.ask or *.ASK and can be opened with notepad.

The 42 digits and 84 digits are random characters with combination of numeric and alphabets.

First 2 digits always are "00" while "01" on 43th & 44th digits.

Please help me build a batch file to do conversion. Thanks in advance.Sorry we can't help with homework.

In the rules.sorry for my bad english.

i think you got me wrong.

what i meant in my first post . . . i wasnt study / attend my programming class (that was long ago) and i am a working man now.

i am lack of batch programming knowlegde, thats why i need help / ASSISTANT from you all.

hope to get solution right in this great place . . . use set to get substring of string. set/? for more explanation.
use for loop to enumerate *.ASK file inside a folder

is your ASK file contents always 3 LINES?thanks for reply.

ASK content always 3 lines. this is an alternative, if you are not restricted at all from downloading gawk for windows.
Code: [Select]BEGIN{print "[CERT_PROG_DATA_IN]"}
NR==3 && length==42{ rap=substr($0,3); ape=""}
NR==3 && length==84{ rap=substr($0,3,40); ape=substr($0,45)}
END{
print "RAP_PUBLIC_ID=" rap
print "APE_PUBLIC_ID=" ape
}
save the above as script.awk and on command line
Code: [Select]C:\test>more file.txt
005974e21c

00175002152F416B5604FF78AD18A7EBFEA6DF897E

C:\test>gawk -f script.awk file.txt
[CERT_PROG_DATA_IN]
RAP_PUBLIC_ID=175002152F416B5604FF78AD18A7EBFEA6DF897E
APE_PUBLIC_ID=

C:\test>more file.txt
005974e21c

00079001179ACB015460056A55ADCCEFA83FC835E40129899427274E1BF4C440EA3B11F1B016E1F80616

C:\test>gawk -f script.awk file.txt
[CERT_PROG_DATA_IN]
RAP_PUBLIC_ID=079001179ACB015460056A55ADCCEFA83FC835E4
APE_PUBLIC_ID=29899427274E1BF4C440EA3B11F1B016E1F80616
or as one liner
Code: [Select]C:\test>gawk "NR==3{ printf \"[CERT_PROG_DATA_IN]\nRAP_PUBLIC_ID=%s\nAPE_PUBLIC_ID=%s\n\",substr($0,3,40),substr($0,45)}" file.txt
[CERT_PROG_DATA_IN]
RAP_PUBLIC_ID=079001179ACB015460056A55ADCCEFA83FC835E4
APE_PUBLIC_ID=29899427274E1BF4C440EA3B11F1B016E1F80616
batch version:
Code: [Select]@echo off & setlocal

for /f "usebackq skip=2 delims=" %%a in ("%~1") do set s=%%a
echo [CERT_PROG_DATA_IN]
echo RAP_PUBLIC_ID=%s:~2,40%
echo APE_PUBLIC_ID=%s:~44%
output:
Code: [Select]C:\>ask data42.txt
[CERT_PROG_DATA_IN]
RAP_PUBLIC_ID=175002152F416B5604FF78AD18A7EBFEA6DF897E
APE_PUBLIC_ID=

C:\>ask data84.txt
[CERT_PROG_DATA_IN]
RAP_PUBLIC_ID=079001179ACB015460056A55ADCCEFA83FC835E4
APE_PUBLIC_ID=29899427274E1BF4C440EA3B11F1B016E1F80616
thanks for reply guys....

@Reno,

i created bat file and run it, but it didnt converting the ASK file. Any idea ?

@ghostdog74,

thanks for reply . . . i have no idea how to operate gawk . .Quote from: kent_lkc on April 02, 2009, 04:22:01 AM

thanks for reply guys....

@Reno,

i created bat file and run it, but it didnt converting the ASK file. Any idea ?
most probably you did not redirect to new file.

Quote
@ghostdog74,

thanks for reply . . . i have no idea how to operate gawk . .
too bad.yup, as ghostdog suggest, redirect it to new file, example as below.
Code: [Select]C:\>ask data42.txt>result.txt

C:\>type result.txt
[CERT_PROG_DATA_IN]
RAP_PUBLIC_ID=175002152F416B5604FF78AD18A7EBFEA6DF897E
APE_PUBLIC_ID=
or if you want to create the new file from inside batch, you could modify the code.
eg.
>>result.txt echo [CERT_PROG_DATA_IN]


Discussion

No Comment Found