Sponsored Content
Top Forums Shell Programming and Scripting sed replacing specific characters and control characters by escaping Post 302634639 by Scrutinizer on Thursday 3rd of May 2012 03:40:08 PM
Old 05-03-2012
I tried it, and like that it did not remove all characters, but like this it did:
Code:
LANG=C tr -d '[\200-\377]' < input > output

Code:
$ printf "%s\n" 'An preost wes on leoden, Laȝamon was ihoten
He wes Leovenağes sone -- liğe him be Drihten.
He wonede at Ernleȝe at æğelen are chirechen,
Uppen Sevarne staşe, sel şar him şuhte,
Onfest Radestone, şer he bock radde.' |
LANG=C tr -d '[\200-\377]'
An preost wes on leoden, Laamon was ihoten
He wes Leovenaes sone -- lie him be Drihten.
He wonede at Ernlee at elen are chirechen,
Uppen Sevarne stae, sel ar him uhte,
Onfest Radestone, er he bock radde.


Last edited by Scrutinizer; 05-03-2012 at 04:47 PM..
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to replace control characters using sed?

How can I use sed to replace a ctrl character such as 'new line' (\0a) to something else? Or any other good command can do this job? Thanks, Hillxy (5 Replies)
Discussion started by: hillxy
5 Replies

2. Shell Programming and Scripting

replacing specific characters in a string

Hi Friends, Following is an output of a script OPWQERIUTYKLSADFJHGXZNMCVBWQOPERIUTYKLSADFJHGXZNMCVB I want to replace above string's 11 to 17 character by ******* (7 stars) How can it be done? Please somebody guide me. (6 Replies)
Discussion started by: anushree.a
6 Replies

3. Shell Programming and Scripting

help on sed replacing special characters

Hello, I have a file with many lines with below format: \abc\\1234 jkl\\567 def\\345 \pqr\\567 \xyz\\234 Here, i need to do 2 things. 1. replace \\ with \ 2. remove starting \ so output to be as below: (11 Replies)
Discussion started by: prvnrk
11 Replies

4. Shell Programming and Scripting

Escaping Special characters

I want to append the following line to /var/spool/cron/root: */7 * * * * /root/'Linux CPU (EDF).sh' > /dev/null 2>&1 How to accomplish this using echo? ---------- Post updated at 04:09 PM ---------- Previous update was at 04:07 PM ---------- "Linux CPU (EDF)" is actually stored in a... (11 Replies)
Discussion started by: proactiveaditya
11 Replies

5. UNIX for Dummies Questions & Answers

Escaping non-readable characters using grep, sed or awk

I'm trying to parse out DNS logs from dozens of different domain controllers over a large period of time. The logs are rolled up into individual text files by size, which may contain only a portion of a day's activity or several day's worth (depending on amount of activity). I'm splitting them by... (4 Replies)
Discussion started by: seanwpaul
4 Replies

6. UNIX for Dummies Questions & Answers

sed replacing in vi, / characters in the middle

I tried to replace the following in vi: old: 'e/thesis/pp/zones/zones' new: 'd/so162/fix/pp' For that, I used: :%s/e/thesis/pp/zones/zones/d/so162/fix/pp/g but doesn't work, a trailing character error message appeared. How can I get it? Thanks in advance (3 Replies)
Discussion started by: Gery
3 Replies

7. Shell Programming and Scripting

Sed - merge lines bw 2 specific characters

Hi, I have a bash script and I am looking for a command that will merge specific lines together. Sample Data: registration time = 1300890272 Id = 1 setd = 0 tagunt = 26 tagId=6, length=8, value= tagId=9, length=5, value= tagId=7, length=2, value= tagId=16, length=2, value= tagId=32,... (8 Replies)
Discussion started by: Winsarc
8 Replies

8. Shell Programming and Scripting

How delete characters of specific line with sed?

Hi, I have a text file with some lines like this: /MEDIA/DISK1/23568742.MOV /MEDIA/DISK1/87456321.AVI /MEDIA/DISK2/PART1/45753131.AVI /IMPORT/44452.WAV ... I want to remove the last 12 characters in each line that it ends "AVI". Should look like this: /MEDIA/DISK1/23568742.MOV... (12 Replies)
Discussion started by: inaki
12 Replies

9. Shell Programming and Scripting

Replacing specific characters using sed

Hi, I have a text file which is output from a server and it lists all the files in a specific volume. However, the volume name appears as volume_name:. I would like to replace this with \\volume_name\volume_name. This is not a problem in itself as I can use sed to globally look for the... (8 Replies)
Discussion started by: vnayak
8 Replies

10. HP-UX

Replacing control characters in HPUX

Hello dears, Please tell me how can I replace control characters with normal string. I have a file that contains normal string and ^A ^C control characters. I tried to use sed and awk without any luck. sed 's/^A/foo/g' text > text1 //not worked sed 's/\x01/foo/g' text > text1 ... (6 Replies)
Discussion started by: sembii
6 Replies
SNMPUSM(1)							     Net-SNMP								SNMPUSM(1)

NAME
snmpusm - creates and maintains SNMPv3 users on a network entity SYNOPSIS
snmpusm [COMMON OPTIONS] create USER [CLONEFROM-USER] snmpusm [COMMON OPTIONS] delete USER snmpusm [COMMON OPTIONS] cloneFrom USER CLONEFROM-USER snmpusm [COMMON OPTIONS] [-Ca] [-Cx] passwd OLD-PASSPHRASE NEW-PASSPHRASE [USER] snmpusm [COMMON OPTIONS] <-Ca | -Cx> -Ck passwd OLD-KEY-OR-PASSPHRASE NEW-KEY-OR-PASSPHRASE [USER] snmpusm [COMMON OPTIONS] [-Ca] [-Cx] changekey [USER] DESCRIPTION
snmpusm is an SNMP application that can be used to do simple maintenance on the users known to an SNMP agent, by manipulating the agent's User-based Security Module (USM) table. The user needs write access to the usmUserTable MIB table. This tool can be used to create, delete, clone, and change the passphrase of users configured on a running SNMP agent. OPTIONS
Common options for all snmpusm commands: -CE ENGINE-ID Set usmUserEngineID to be used as part of the index of the usmUserTable. Default is to use the contextEngineID (set via -E or probed) as the usmUserEngineID. -Cp STRING Set the usmUserPublic value of the (new) user to the specified STRING. Options for the passwd and changekey commands: -Ca Change the authentication key. -Cx Change the privacy key. -Ck Allows to use localized key (must start with 0x) instead of passphrase. When this option is used, either the -Ca or -Cx option (but not both) must also be used. CREATING USERS
An unauthenticated SNMPv3 user can be created using the command snmpusm [OPTIONS] create USER This constructs an (inactive) entry in the usmUserTable, with no authentication or privacy settings. In principle, this user should be useable for 'noAuthNoPriv' requests, but in practise the Net-SNMP agent will not allow such an entry to be made active. In order to activate this entry, it is necessary to "clone" an existing user, using the command snmpusm [OPTIONS] cloneFrom USER CLONEFROM-USER The USER entry then inherits the same authentication and privacy settings (including pass phrases) as the CLONEFROM user. These two steps can be combined into one, by using the command snmpusm [OPTIONS] create USER CLONEFROM-USER The two forms of the create sub-command require that the user being created does not already exist. The cloneFrom sub-command requires that the user being cloned to does already exist. Cloning is the only way to specify which authentication and privacy protocols to use for a given user, and it is only possible to do this once. Subsequent attempts to reclone onto the same user will appear to succeed, but will be silently ignored. This (somewhat unexpected) behaviour is mandated by the SNMPv3 USM specifications (RFC 3414). To change the authentication and privacy settings for a given user, it is necessary to delete and recreate the user entry. This is not necessary for simply changing the pass phrases (see below). This means that the agent must be initialized with at least one user for each combination of authentication and privacy protocols. See the snmpd.conf(5) manual page for details of the createUser configuration directive. DELETING USERS
A user can be deleted from the usmUserTable using the command snmpusm [OPTIONS] delete USER CHANGING PASS PHRASES
User profiles contain private keys that are never transmitted over the wire in clear text (regardless of whether the administration requests are encrypted or not). To change the secret key for a user, it is necessary to specify the user's old passphrase as well as the new one. This uses the command snmpusm [OPTIONS] [-Ca] [-Cx] passwd OLD-PASSPHRASE NEW-PASSPHRASE [USER] After cloning a new user entry from the appropriate template, you should immediately change the new user's passphrase. If USER is not specified, this command will change the passphrase of the (SNMPv3) user issuing the command. If the -Ca or -Cx options are specified, then only the authentication or privacy keys are changed. If these options are not specified, then both the authentication and privacy keys are changed. snmpusm [OPTIONS] [-Ca] [-Cx] changekey [USER] This command changes the key in a perfect-forward-secrecy compliant way through a diffie-helman exchange. The remote agent must support the SNMP-USM-DH-OBJECTS-MIB for this command to work. The resulting keys are printed to the console and may be then set in future command invocations using the --defAuthLocalizedKey and --defPrivLocalizedKey options or in your snmp.conf file using the defAuthLocalizedKey and defPrivLocalizedKey keywords. Note that since these keys are randomly generated based on a diffie helman exchange, they are no longer derived from a more easily typed password. They are, however, much more secure. To change from a localized key back to a password, the following variant of the passwd sub-command is used: snmpusm [OPTIONS] <-Ca | -Cx> -Ck passwd OLD-KEY-OR-PASSPHRASE NEW-KEY-OR-PASSPHRASE [USER] Either the -Ca or the -Cx option must be specified. The OLD-KEY-OR-PASSPHRASE and/or NEW-KEY-OR-PASSPHRASE arguments can either be a passphrase or a localized key starting with "0x", e.g. as printed out by the changekey sub-command. EXAMPLES
Let's assume for our examples that the following VACM and USM configurations lines were in the snmpd.conf file for a Net-SNMP agent. These lines set up a default user called "initial" with the authentication passphrase "setup_passphrase" so that we can perform the initial setup of an agent: # VACM configuration entries rwuser initial # lets add the new user we'll create too: rwuser wes # USM configuration entries createUser initial MD5 setup_passphrase DES Note: the "initial" user's setup should be removed after creating a real user that you grant administrative privileges to (like the user "wes" we'll be creating in this example. Note: passphrases must be 8 characters minimum in length. Create a new user snmpusm -v3 -u initial -n "" -l authNoPriv -a MD5 -A setup_passphrase localhost create wes initial Creates a new user, here named "wes" using the user "initial" to do it. "wes" is cloned from "initial" in the process, so he inher- its that user's passphrase ("setup_passphrase"). Change the user's passphrase snmpusm -v 3 -u wes -n "" -l authNoPriv -a MD5 -A setup_passphrase localhost passwd setup_passphrase new_passphrase After creating the user "wes" with the same passphrase as the "initial" user, we need to change his passphrase for him. The above command changes it from "setup_passphrase", which was inherited from the initial user, to "new_passphrase". Test the new user snmpget -v 3 -u wes -n "" -l authNoPriv -a MD5 -A new_passphrase localhost sysUpTime.0 If the above commands were successful, this command should have properly performed an authenticated SNMPv3 GET request to the agent. Now, go remove the vacm "group" snmpd.conf entry for the "initial" user and you have a valid user 'wes' that you can use for future trans- actions instead of initial. WARNING
Manipulating the usmUserTable using this command can only be done using SNMPv3. This command will not work with the community-based ver- sions, even if they have write access to the table. SEE ALSO
snmpd.conf(5), snmp.conf(5), RFC 3414 4th Berkeley Distribution 22 Oct 2005 SNMPUSM(1)
All times are GMT -4. The time now is 02:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy