Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Check if file is EBCDIC or ASCII format Post 303011849 by drysdalk on Wednesday 24th of January 2018 11:19:16 AM
Old 01-24-2018
Hi,

I think I can see where you might have gone a little bit wrong here. I assume that when you run:

Code:
grep -q data "$type"

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:

Code:
if echo "$type" | grep "data"

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.

Hope this helps.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check whether a given file is in ASCII format and data is tab-delimited

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)
Discussion started by: Mandab
9 Replies

2. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

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)
Discussion started by: gaur.deepti
5 Replies

3. Shell Programming and Scripting

How to convert ebcdic file to ascii file?

How to convert ebcdic file to ascii file? (1 Reply)
Discussion started by: superuser123
1 Replies

4. UNIX for Dummies Questions & Answers

How to convert ebcdic file to ascii file?

How to convert ebcdic file to ascii file? (1 Reply)
Discussion started by: superuser123
1 Replies

5. Shell Programming and Scripting

How to check if the file has EBCDIC or ascii characters

Hi, is there a way to check if the initial few characters are ebcdic or ascii in a file? (1 Reply)
Discussion started by: ahmedwaseem2000
1 Replies

6. UNIX for Dummies Questions & Answers

Help! EBCDIC format to ASCII

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)
Discussion started by: hrchl86
12 Replies

7. Shell Programming and Scripting

EBCDIC Format to ASCII

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)
Discussion started by: koti_rama
8 Replies

8. Red Hat

Unable to convert EBCDIC file to ASCII file

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)
Discussion started by: sethmj
3 Replies

9. Programming

Ebcdic to ascii

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)
Discussion started by: tostay2003
19 Replies

10. UNIX for Beginners Questions & Answers

Convert EBCDIC(.DAT) FILE into ASCII FILE

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)
Discussion started by: JSM
2 Replies
uuencode(5)							File Formats Manual						       uuencode(5)

NAME
uuencode file format DESCRIPTION
The command generates files in a format that allows them to be successfully transferred by systems which strip the high bit from an 8-bit byte. decodes uuencoded files. The uuencode file format consists of three sections: header, body, and trailer. The header is a line is of the form: begin 644 "filename.ext" where "644" is a -format permissions byte for the file and "filename.ext" is the name of the encoded file. The body section is the encoded representation of the source file. Three bytes of input file data are encoded into four bytes of output data. The 24 input bits are divided up into four pieces of six bits each. The integer value 32 (the ASCII value for the space character) is added to each of these pieces to move them outside of the range of control characters. To avoid using the space character in the encoding, pieces with value zero are encoded using backquote (ASCII value 96) instead of zero. The resulting character is one of the this set (ASCII values 96,33-95): A line itself contains three segments: a length character (encoded using the "add a space" algorithm described above), the body of the line, typically (although not required to be) 60 output characters long, representing 45 input bytes, and (of course) a linefeed. The length character specifies the number of valid input bytes on the line (so, for a line which is 60 encoded bytes, the length value would be 45). Decoding programs should decode no further than the specified length on a single line. The trailer, which must exist, consists of a single backquote ("`", ASCII 96) character on a line by itself, directly followed by on a line by itself. is the canonical filename extension for uuencoded files. BUGS
uudecode does not read all permutations of the file format described in this man page. Ancient versions of uuencode used a space character (ASCII 32) in the encoding to represent zero. Many (arguably broken) mailers and trans- port agents stripped, rewrapped, or otherwise mangled this format, so the space was later changed to the backquote, ASCII 96. Decoders may attempt to read the older format if they wish, though it's unlikely to be encountered in practice at this point in time. The uuencode encoding method is highly ASCII-centric. In particular, the character set used doesn't work well on EBCDIC-based systems. (EBCDIC, generally used by IBM mainframes, is an old alternative character encoding; most computers use ASCII instead). Many variants of uuencode on various platforms generate different forms of line checksums, using to represent the checksum one or more encoded characters after the last counted character in a line. Because these formats are different and impossible to distinguish (with certainty), such characters should be ignored by decoding implementations. The uuencode encoding format has no provisions for segmented files. Writers of segmenting utilities should be careful to avoid using char- acter sequences that may naturally occur in the encoding (such as sequences of dashes ("---")) to divide sections. SEE ALSO
The MIME Base64 encoding (documented in RFC 2045) is a consistent, cross-platform-savvy message encoding which should be used in place of UUEncode wherever possible. The Unix-Hater's Handbook (IDG, 1994) identifies the folly of the older zero-encoded-as-space versions of uuencode. Apple Computer, Inc. May, 2001 uuencode(5)
All times are GMT -4. The time now is 02:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy