Sponsored Content
Top Forums Shell Programming and Scripting Find/replace alpha characters in string Post 302932416 by goodbenito on Wednesday 21st of January 2015 11:47:00 AM
Old 01-21-2015
Find/replace alpha characters in string

Hi,
I would like to find a 3-letter character series in a string/variable and replace it with x's.

An example set of strings is:

Code:
563MS333_101_afp_400-100_screening
563MS333_104-525_rjk_525_screening
563MS333_110_dlj_500-100_w24
563MS333_888-100_mmm_424_screening

The only constants are: 565MS333 and the time points at the end of each string (so 'screening', 'w24', 'w48', 'w96'). The rest can be variable.

I am trying to replace the 3-alpha characters in between the 3-digit numbers with x's (so, *_xxx_*). The 3 alpha characters are usually between underscores, but not always.

Thanks for the help/input!

Last edited by Scrutinizer; 01-23-2015 at 01:59 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string and delete extra characters

Hopefully someone can help out here. This is probably fairly basic, but I've searched and tried several variations of the solutions presented in these forums, so I'll go ahead and ask. How can I locate a string in a file, delete the characters after the string and then replace the string with a... (2 Replies)
Discussion started by: slaubhan
2 Replies

2. Shell Programming and Scripting

Replace characters in a string using their ascii value

Hi All, In the HP Unix that i'm using when i initialise a string as Stalled="'30¬G'" Stalled=$Stalled" '30¬C'", it is taking the character ¬ as a comma. I need to grep for 30¬G 30¬C in a file and take its count. But since this character ¬ is not being understood, the count returns a zero. The... (2 Replies)
Discussion started by: roops
2 Replies

3. UNIX for Dummies Questions & Answers

Help with find and replace w/string containing special characters

Can I get some help on this please, I have looked at the many post with similar questions and have tried the solutions and they are not working for my scenario which is: I have a text file (myfile) that contains b_log=$g_log/FILENAME.log echo "Begin processing file FILENAME " >> $b_log ... (4 Replies)
Discussion started by: CAGIRL
4 Replies

4. Shell Programming and Scripting

search and replace characters in one string

I have lines like: Dog Cat House Mouse Dog Cat House Mouse Dog Cat House Mouse Dog Cat House Mouse I'd like to replace characters only in $3. H -> Z s -> W e -> x Resulting in something like (where $1, $2, and $4 are not changed): Dog Cat ZouWx Mouse Dog Cat ZouWx Mouse... (3 Replies)
Discussion started by: dcfargo
3 Replies

5. Shell Programming and Scripting

find replace a pattern and following characters in a word

Suppose that I have a string "one:#red two:#yellow three:#gr'een four:#blu^e" and I want to replace the pattern :# and the following characters in the word with nothing. The output string should look "one two three four" How can I do this with sed. Some points to consider (a) the last word in... (1 Reply)
Discussion started by: superuser84
1 Replies

6. Shell Programming and Scripting

Find number of characters in a column and replace

Hi all, I want to count total no. of characters in a column. and if no. of charaters are more than 3 then it must replace it by splitted string. ie, it must place a space after 3 characters. Ex: 21 435g asd3dd jklfjwe wer column number 3 has 4 alphanumeric character, so it must be splitted... (3 Replies)
Discussion started by: CAch
3 Replies

7. Shell Programming and Scripting

Replace characters in string with awk gsub

Hi I have a source file that looks like a,b,c,d,e,f,g,h,t,DISTI(USD),MSRP(USD),DIST(EUR),MSRP(EUR),EMEA-DISTI(USD),EMEA-MSRP(USD),GLOBAl-DISTI(USD),GLOBAL-MSRP(USD),DISTI(GBP), MSRP(GBP) I want to basically change MSRP(USD) to MSRP,USD and DIST(EUR) to DIST,EUR and likewise for all i'm using... (3 Replies)
Discussion started by: r_t_1601
3 Replies

8. Shell Programming and Scripting

Find and replace with 0 for characters in a specific position

Need command for position based replace: I need a command to replace with 0 for characters in the positions 11 to 20 to all the lines starts with 6 in a file. For example the file ABC.txt has: abcdefghijklmnopqrstuvwxyz 6abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz... (4 Replies)
Discussion started by: thangabalu
4 Replies

9. Shell Programming and Scripting

Help to replace the string with special characters

{"name":"alR_pl-ENVIRONMENT_192_168_211_123_sDK_PROVISION_7","description":"aLR_pl-ENVIRONMENT_192_168_211_123_sDK_PROVISION_7","json_class":"Chef::Role","default_attributes":{},"override_attributes":{"yoapp":{"jboss":"5.1.0","port":"2243","warname":"soap","datacenter":"alR","ip":"192.168.211.123","... (3 Replies)
Discussion started by: nikhil jain
3 Replies

10. Shell Programming and Scripting

sed replace nth characters with string

Hi, I hope you can help me out please? I need to replace from character 8-16 with AAAAAAAA and the rest should stay the same after character 16 gtwrhtrd11111111rjytwyejtyjejetjyetgeaEHT wrehrhw22222222hytekutkyukrylryilruilrGEQTH hrwjyety33333333gtrhwrjrgkreglqeriugn;RUGNEURGU ... (4 Replies)
Discussion started by: stinkefisch
4 Replies
wctype(3)						     Library Functions Manual							 wctype(3)

NAME
wctype - Gets a handle to classify wide characters LIBRARY
Standard C Library (libc) SYNOPSIS
#include <wctype.h> wctype_t wctype( const char *property); The following prototype for wctype() does not conform to current industry standards and is supported only for backward compatibility: #include <wchar.h> wctype_t wctype( char *property); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: wctype(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to a string that identifies a character class, or property. DESCRIPTION
The wctype() function obtains a handle for valid property names for wide characters, as defined in the current locale. The handle can then be used as the wc_prop parameter in a subsequent call to the iswctype() function to check whether a wide character has this property. (See the iswctype(3) reference page.) Values returned by the wctype() function are valid until the setlocale() function modifies the value of the LC_CTYPE environment variable. The property parameter can have a value equal to one of the basic character classes or to any other character class that is defined for a locale. The characters included in each class are specified in the locale definition file (see the localedef(1) and locale(4) reference pages for more information). The basic character classes are as follows: A combination of the classes alpha and digit. Alphabetic (letter) characters. This class automatically includes characters in the upper and lower classes. Blank char- acters, such as the space or tab character. Control characters. This class does not include characters in the alpha or print class. Numeric digit characters. This class includes the following characters: 0 1 2 3 4 5 6 7 8 9 Graphic characters for printing. This class does not include characters in the space or cntrl class but includes all characters in the alpha, digit, and punct classes. Lowercase characters. This class does not include characters in the cntrl, digit, punct, or space class. At a minimum, the lower class includes the 26 lowercase US-ASCII characters. These are: a b c d e f g h i j k l m n o p q r s t u v w x y z Print characters. This class includes characters in the graph and space classes but does not include characters in the cntrl class. Punctuation characters. This class does not include characters in the space, alpha, digit, or cntrl class. Space characters. At a minimum, this class includes the space, form-feed, newline, carriage-return, tab, and vertical-tab characters. Uppercase characters. At a minimum, this class includes the 26 uppercase US ASCII characters. These are: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Hexadecimal characters. This class includes the following characters: 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f For the list of supplemental properties that can be defined in Unicode locales, see the locale(4) reference page. On Tru64 UNIX systems, Unicode character properties are defined only in locales whose names end in .UTF-8. RETURN VALUES
On successful completion, the wctype() function returns a value of type wctype_t, which is a handle for valid property names in the current locale. If the property parameter specifies a character class that is not valid for the current locale, the function returns the value 0 cast to wctype_t. RELATED INFORMATION
Commands: localedef(1) Files: locale(4) Functions: ctype(3), iswctype(3), setlocale(3), towupper(3), wctrans(3) delim off wctype(3)
All times are GMT -4. The time now is 03:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy