So, i have this requirement where i need to check the file format, whether it's EBCDIC or ASCII, and based on format retrieve the information from that file:
i tried below code:
i get output if file is ebcdic:
if file is ascii:
now my requirement is i need to do some operations if file is ebcdic and some if file is ascii:
output:
firstly its not searching the word data correctly in $type variable and its showing something like no such file or directory, can anyone guide me where i am going wrong, and also what will the best approach for this requirement.
TIA
I think I can see where you might have gone a little bit wrong here. I assume that when you run:
you're attempting to see if the string "data" occurs in the contents of the variable "$type", which will indeed be correctly populated with the output of the file command. However, that's not what grep does. The grep command specifically searches the contents of files, and nothing else.
So what's going wrong here is that grep is trying to search for the string "data" in a file on disk in the current directory called (e.g. in the case of an ASCII file) "test: ASCII text", which does not exist.
If you want to check for the contents of a variable rather than a file, there's a few ways you could do that. Probably one of the easiest changes for you to make in your script would be to do a test like this instead:
This would cause grep to treat sandard input as its file, into which we are piping the output of the echo "$type" command. So this would ultimately check to see if the variable "$type" contained the string "data", which is I think what you're wanting to do.
grep takes a file for input, not the contents of a shell variable. To analyse a shell variable, you can use the test (or [ ) or case command, or - in more recent shells - the [[ compound command. For example (please be aware that my file command outputs different results for ebcdic):
It would help to know the source of this data--is it mostly letters and numbers or are there a lot of special characters. If you have very few characters (like Greek letters, graphics, or math symbols) higher than x'7f', you and assume it is ASCII. In EBCDIC alphabetic and numeric characters are all higher than that. Also, a space in ASCII is x'20' while an EBCDIC space is x'40', the ASCII symbol for the at sign "@". Perhaps compare the number of at signs to the file size?
This table: Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion is a good place to start.
Packed decimal has little to do with EBCDIC or ASCII. Each byte contains two decimal digits except the last byte may contain a sign like x'C' for positive, x'D' for negative, and x'F' for unsigned.
In COBOL, a signed five digit field would be represented with
and would occupy three bytes. In hex, the number -12345 would be x'12 34 5D'.
Hi Team,
I am having 100 EBCDIC files (i.e. DAT extension) and need to convert them into ASCII File by unix shell script.
I tried with DD Command but its not providing output as expected.
Sample Text:
------------------
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Expected Output:... (2 Replies)
Hi,
I want to convert ebcdic values to ascii values. Are there anyany specific c++ libraries with g++ compiler, which can do it ?
gcc version 4.1.2 20080704 (Red Hat 4.1.2-54) (19 Replies)
Hello all,
To give you all a little bit of background. We recently migrated from HP-UX to Redhat Linux and one of the command I used to run on HP-UX to convert an EBCDIC file to ASCII file isn't working on Linux. The code is as follow:
cat workout2.dat | dd cbs=250 conv=block conv=ascii... (3 Replies)
Hi,
we have source file with EBCDIC format(Main Frame files) where we receving from source system.
I would like to convert the EBCDIC format file to unix systemformat(ex: .csv,txt )
I have wrote script like:
dd if=<SRCPATH>yyy.xxx.RB065 of=<SRCPATH>/output.csv ibs=800 cbs=80... (8 Replies)
Hi everyone,
I have a 70MB EBCDIC file, with record length 102, block size 32742 and IBM standard label.
I commanded
dd if=input file of=outputfie ibs=32742 cbs=102 conv=ascii
but I still don't get a viewable file under ASCII.
Can anyone told me what's the problem?
Do I need... (12 Replies)
Hi
I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like ..ݡ.ݡ ) in it. I want to standardize the file into ASCII format & later use that as source .
Can any one suggest a way a logic to convert such... (5 Replies)
Hi All,
Please help me out with a script which checks whether a given file say abc.txt is in ASCII format and data is tab-delimited. If the condition doesn't satisfy then it should generate error code "100" for file not in ASCII format and "105" if it is not in tab-delimited format.
If the... (9 Replies)