Sponsored Content
Top Forums Shell Programming and Scripting Shell script remove bad character Post 302713225 by kshji on Wednesday 10th of October 2012 11:30:29 AM
Old 10-10-2012
Code:
# ascii 169 = oct 251
tr -d '\251'

'[\252-\254]' # all ascii between \252 and \254
or list some chars
'\251\253\221'

\NNN = octal value

If you need conversion tool, ex. in ksh93 you can use builtin:
Code:
dec=169
typeset -i 8 oct
oct=$dec
echo $oct
# or binary
typeset -i 2 bin
bin=$dec
echo $bin


Last edited by kshji; 10-10-2012 at 12:38 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to Remove Garbage Character

Hello, Whenever I transfer files between machines, I find a garbage character (^M) being appended to the end of every line of the file. Can you suggest a script wherein I can eliminate the garbage character. I tried sed 's/^M//g' < filename > filename1 ...but it doesn't work. Also, this... (4 Replies)
Discussion started by: Eddie_The_Head
4 Replies

2. Shell Programming and Scripting

Script to remove first character if it is zero

Hi All, I have a input like this. 01 i want the output like this. 1 But if the input file is like 11 i should not do anything. Can anyone please help to get a command to do this. thanks, Giri. ---------- Post updated at 02:11 AM ---------- Previous update was at 02:04 AM ----------... (5 Replies)
Discussion started by: girish.raos
5 Replies

3. Shell Programming and Scripting

shell script to remove the last character(.) of a string

hi I have a list of words in a text file. these words are appended by "." at their end. They look something like this. word1. word2. word3. word4. word5. I need to remove the last character "." from all the words. The output must look something like this. word1 word2 word3... (7 Replies)
Discussion started by: ss3944
7 Replies

4. Shell Programming and Scripting

Bad substitution errors in shell script

Hello, I was hoping for a second pair of eyes or a little bit of help figuring out what my error is in a script. I did some searching in the forums and didn't find anything so please forgive me if it a similar problem has been discussed before. My script accepts normal user arguments; however,... (2 Replies)
Discussion started by: Jackinthemox
2 Replies

5. Shell Programming and Scripting

Bad character in output file

Hi All, I am facing some problems with bad characters in my file.For example- 00000000509 TCI DEVOFFERS= 1 Now I want to remove all bad characters and replace with *. Please suggest some solution. Along with that How to mention a range of ASCII values in TR command to replace? ... (2 Replies)
Discussion started by: bghosh
2 Replies

6. Linux

Linux script to remove a character in a file based on position.

Greetings, We have a requirement where we need to loop in a fixed width file in linux and remove a character based on a position for every record. It would highly appreciate if someone can help to automate this. Appreciate your time and help! Regards (3 Replies)
Discussion started by: mailme0205
3 Replies

7. Shell Programming and Scripting

Script to search for a character in files in a Directory & remove it

Hi All, Am new to both Unix & this Forum - Need some help on a script that I am trying to write: In a Directory i have few text files which might or might not contain some text that I am trying to find. Once that text is found in any of the files, it needs to be removed from the file ... (6 Replies)
Discussion started by: rituparna_gupta
6 Replies

8. Shell Programming and Scripting

Bad substitution error in shell script

I have script data.sh which has following error. Script Name : data.sh #!/bin/sh infile=$1 len=${#infile} echo $len texfile=${infile:0:$len-4} echo $texfile run command ./data.sh acb.xml I get following error message: (5 Replies)
Discussion started by: man4ish
5 Replies

9. Shell Programming and Scripting

ksh - Get last character from string - Bad Substitution error

I want to get the last character from my machine name using the following code, the default shell is bash, the script runs in ksh. I get 'bad' substitution error on running the script, but works fine if run using dot and space. Why? $ echo $0 bash $ cat -n myenv.sh 1 ... (8 Replies)
Discussion started by: ysrini
8 Replies

10. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies
oct(n)																	    oct(n)

__________________________________________________________________________________________________________________________________________________

NAME
oct - Encoding "oct" SYNOPSIS
package require Tcl ?8.2? package require Trf ?2.1.4? oct ?options...? ?data? _________________________________________________________________ DESCRIPTION
The command oct is one of several data encodings provided by the package trf. See trf-intro for an overview of the whole package. This encoding transforms every byte in the input into a sequence of 3 characters containing the octal representation of the byte. For example % oct -mode encode Z 132 oct ?options...? ?data? -mode encode|decode This option has to be present and is always understood by the encoding. For immediate mode the argument value specifies the operation to use. For an attached encoding it specifies the operation to use for writing. Reading will automatically use the reverse operation. See section IMMEDIATE versus ATTACHED for explana- tions of these two terms. Beyond the argument values listed above all unique abbreviations are recognized too. Encode converts from arbitrary (most likely binary) data into the described representation, decode does the reverse . -attach channel The presence/absence of this option determines the main operation mode of the transformation. If present the transformation will be stacked onto the channel whose handle was given to the option and run in attached mode. More about this in section IMMEDIATE versus ATTACHED. If the option is absent the transformation is used in immediate mode and the options listed below are recognized. More about this in section IMMEDIATE versus ATTACHED. -in channel This options is legal if and only if the transformation is used in immediate mode. It provides the handle of the channel the data to transform has to be read from. If the transformation is in immediate mode and this option is absent the data to transform is expected as the last argument to the transformation. -out channel This options is legal if and only if the transformation is used in immediate mode. It provides the handle of the channel the generated transformation result is written to. If the transformation is in immediate mode and this option is absent the generated data is returned as the result of the com- mand itself. IMMEDIATE VERSUS ATTACHED
The transformation distinguishes between two main ways of using it. These are the immediate and attached operation modes. For the attached mode the option -attach is used to associate the transformation with an existing channel. During the execution of the com- mand no transformation is performed, instead the channel is changed in such a way, that from then on all data written to or read from it passes through the transformation and is modified by it according to the definition above. This attachment can be revoked by executing the command unstack for the chosen channel. This is the only way to do this at the Tcl level. In the second mode, which can be detected by the absence of option -attach, the transformation immediately takes data from either its com- mandline or a channel, transforms it, and returns the result either as result of the command, or writes it into a channel. The mode is named after the immediate nature of its execution. Where the data is taken from, and delivered to, is governed by the presence and absence of the options -in and -out. It should be noted that this ability to immediately read from and/or write to a channel is an historic artifact which was introduced at the beginning of Trf's life when Tcl version 7.6 was current as this and earlier versions have trouble to deal with characters embedded into either input or output. SEE ALSO
ascii85, base64, bin, hex, oct, otp_words, quoted-printable, trf-intro, uuencode KEYWORDS
bin, encoding, hex, oct COPYRIGHT
Copyright (c) 1996-2003, Andreas Kupries <andreas_kupries@users.sourceforge.net> Trf transformer commands 2.1.4 oct(n)
All times are GMT -4. The time now is 05:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy