Removing only Prefix string (!)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing only Prefix string (!)
# 1  
Old 12-15-2014
Removing only Prefix string (!)

Hello everyone,

I want to remove only prefix ME_ from all the values that are present in the FILEA. Below code I'm using for this.

Code:
sed 's/ME\_//g' FILEA > FILEB

Using the above code, all ME_ values are getting removed from the file. But the problem here is I want to remove only Prefix ME_ , but the above code removing all ME_ wherever it's present in the string in file.

Example:
Code:
Input - 
ME_ABC_X,ME_DME_X, ME_FCX_X

Output-
ABC_X,DX,FCX_X

But the desired output is:
ABC_X, DME_X, FCX_X

Please advise.

Thanks in advance!
# 2  
Old 12-15-2014
Try using EREs (extended regexes):
Code:
sed -r 's/(^|,| )ME\_/\1/g' file3
ABC_X,DME_X, FCX_X

This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-15-2014
Note sed -r is GNU sed. With it, you could also do this:
Code:
sed 's/\<ME_//g' file

This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 12-15-2014
Code:
perl -pe 's/\bME_//g' FILEA > FILEB

This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 12-16-2014
Thanks RudiC, Scrutinizer and MadeInGermany!
All are worked the way I wanted.

Thanks again!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing string from CSV file by provide removal string from other file

What I need is to remove the text from Location_file.txt from each line matching all entries from Remove_location.txt Location_file.txt FlowPrePaid, h3nmg1cm2,Jamaica_MTAImageFileFlowPrePaid,h0nmg1cm1, Flow_BeatTest,FlowRockTest FlowNewTest,FlowNewTest,h0nmg1cm1 PartiallySubscribed,... (3 Replies)
Discussion started by: ketanraut
3 Replies

2. Shell Programming and Scripting

Extract Uniq prefix from a start and end prefix

Dear All, assume i have a file with content: <Start>6000</Start> <Stop>7599</Stop> the output is: 6000 7000 7100 7200 7300 7400 7599 how should we use any awk, sed, perl can do this task, means to extract the uniq prefixes from the start and stop prefix. Thanks Jimmy (3 Replies)
Discussion started by: jimmy_y
3 Replies

3. Shell Programming and Scripting

Using filename to determine a prefix that needs to be added to string column on file?

Possible filenames: CDD_Whatever.txt DDD_Whatever.txt If the file prefix = CDD, I'd like to prefix every person ID (second column in my examples below) on the file with "c-" If the file prefix = DDD, I'd like to prefix ever person ID with "d-" Input: Desired Output: Any help... (2 Replies)
Discussion started by: lrluis
2 Replies

4. Shell Programming and Scripting

Replace prefix and suffix of a string

Hi, I'm new about shell scripting, and I need to do something like abcd **1234** efgh by abcd '''1234''' efgh I know that command sed helps about change one string by another, but I dont know how to keep whatever is inside **_** and replace * with '. Thanks! (5 Replies)
Discussion started by: selvaya
5 Replies

5. Shell Programming and Scripting

QUERY_STRING with multiples appearances of the same string prefix

I have a shell script and it works pretty well to pull out the query_string contents of a single instance of router= But if I have multiple router= strings, it only pulls out the last one. Is there a way to pull out every router= and if there is a multple string, to egrep them together... (1 Reply)
Discussion started by: numele
1 Replies

6. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies

7. UNIX for Dummies Questions & Answers

how to cut prefix from a string

I have a file: chromosome1:436728 chromosome2:32892 ..... chromosome22:23781 I just want to get the number, not the prefix "chromosomeX", so I want to remove all the prefix ahead of the numbers. How can I do that?? Thanks!!! (PS: give me some very simple command so that I can understand... (4 Replies)
Discussion started by: kaixinsjtu
4 Replies

8. Shell Programming and Scripting

Prefix a string to the contents of a file

Hi all, I have a requirement where in i have to create a temporary file by prefixing a string of special characters to each row of a input file. the input file is '|' delimited. here is the content of input file aaa|1234|axad|123 bbb|qwqw|qw|1334 the output should be ... (5 Replies)
Discussion started by: nvuradi
5 Replies

9. Shell Programming and Scripting

Help removing the prefix of more than 10,000 files

I have more than 10,000 files that all start with "raw_ddd_04_*". How can I remove the prefix on these files in a single command? (8 Replies)
Discussion started by: bbbngowc
8 Replies

10. Shell Programming and Scripting

How to cut prefix from a string?

Hi folks, I have the following parameter setting: export ADMIN_HOST_NAME=http://hostname.com I want to define a new parameter,ADMIN_HOST_NAME_NEW,which based on $ADMIN_HOST_NAME but I need to remove the prefix "http://". The requested result for $ADMIN_HOST_NAME_NEW is hostname.com How... (2 Replies)
Discussion started by: nir_s
2 Replies
Login or Register to Ask a Question