Help on "tr' command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on "tr' command
# 1  
Old 09-07-2010
Help on "tr' command

Hi All,

I was asked to rewrite a script which is working in Solaris to Linux. In the existing script i have following 'tr' command.

Code:
tr -d '\002\003\013\032\001\014\272'  <$INPUT_FILE | tr -cd '[:print:]\n' >$OUTPUT_FILE

Some1 help me to understand this. Here is my understanding,
tr -d option deletes the occurance of '\002\003\013\032\001\014\272' in the input_file and prints with new line character.

Brief abt script, we are extracting our feed file from Aix (mainframe) and loading that in application running in the Linux OS. Since mainframe uses EBCDIC i have to remove some extra character which is not applicable or printable in ascii. So this script is used to remove those non-printable character and load into solaris server successfully. It is my time to convert this into Linux.

thx for help
# 2  
Old 09-07-2010
the numbers in -d ' ' have different meaning.

Code:
 000 NUL  001 SOH  002 STX  003 ETX  004 EOT 005 ENQ  006 ACK  007 BEL   
 010 BS   011 HT†  012 NL   013 VT   014 NP  015 CR   016 SO   017 SI 
 020 DLE  021 DC1  022 DC2  023 DC3  024 DC4 025 NAK  026 SYN  027 ETB
 030 CAN  031 EM   032 SUB  033 ESC  034 FS  035 GS   036 RS   037 US   
 177 DEL

# 3  
Old 09-07-2010
Code:
tr -cd '[:print:]\n'

The second "tr" command deletes every character which is not in the "printing characters" set called ":print:" except a line-feed character "\n".
The first "tr" commands has already removed some characters which are in the "printing characters" set. It is referring to the Octal value of each character (e.g. \003 is the control code Ctrl/C).
The final result contains a subset of the characters which are in the "printing characters" set or line-feed characters.

On my unix computer the explanation of the meaning of ":print:" is in "man 5 regexp". It will probably be a different "man" page in Linux.


The script posted would only make sense if the input file was already in ASCII (not EBCDIC) or perhaps the environment locale has been changed?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

2. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. UNIX for Dummies Questions & Answers

Explanation of "total" field in "ls -l" command output

When I do a listing in one particular directory (ls -al) I get: total 43456 drwxrwxrwx 2 root root 4096 drwxrwxrwx 3 root root 4096 -rwxrwxr-x 1 nobody nobody 3701594 -rwxrwxr-x 1 nobody nobody 3108510 -rwxrwxr-x 1 nobody nobody 3070580 -rwxrwxr-x 1 nobody nobody 3099733 -rwxrwxr-x 1... (1 Reply)
Discussion started by: proactiveaditya
1 Replies

5. UNIX for Dummies Questions & Answers

the meaning of "!:*" in "alias foo 'command\!:*' filename"

Hi: How can I remove my own post? Thanks. (2 Replies)
Discussion started by: phil518
2 Replies

6. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. Shell Programming and Scripting

How to distinguish between "command not found" and "command with no result"

system() call imeplemented in solaris is such a way that: Command not found - return code 1 Command executed successfully without Output - return code 1 how to distinguish between these two based on return code in a c - file? Can you help on this ? (5 Replies)
Discussion started by: iitmadhu
5 Replies

10. UNIX for Advanced & Expert Users

The "PS" command was displaying*terminals named as "SYSCON"

Hi, When typing the command ps -fe.the system is showing a process called SYSCON:confused:.... I am not sure what process is that.I hava a script that kills all command staring with 'sys' but i don't want to kill syscon:( since i think it is some system process:confused: .Please help me to find... (1 Reply)
Discussion started by: kiranjose85
1 Replies
Login or Register to Ask a Question