excise a part of string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers excise a part of string
# 1  
Old 05-26-2009
excise a part of string

Dear all, will appreciate your help with this (supposedly simple) thing.
How to use sed to replace a part of string like this:

(TAGthenwhatever:

into (TAG:

meaning that '(TAG' (known, can be specified to sed and is marked with the '(' at the beginning) will stay and the 'thenwhatever' (until the first occurrence of ':') will go. The whatever can really be whatever but it is not interrupted with blanks (continuous string).

thanks a lot!
# 2  
Old 05-26-2009
Question

Can you please provide a better example, including original text and your desired output?
# 3  
Old 05-26-2009
Quote:
Originally Posted by joeyg
Can you please provide a better example, including original text and your desired output?
the original string would be

....1.08305,((THDEA1_1_PE708:0.47029,...

and, provided that I know the name THDEA,

the line would become 1.08305,((THDEA:0.47029,

The name is known every time I want to make the excision after it. But the surroundings will vary.
# 4  
Old 05-26-2009
Try this:

Code:
sed 's/\(.*THDEA\).*\(:.*\)/\1\2/'

# 5  
Old 05-26-2009
Quote:
Originally Posted by Franklin52
Try this:

Code:
sed 's/\(.*THDEA\).*\(:.*\)/\1\2/'

thanks- really unix is elegant

-----Post Update-----

Quote:
Originally Posted by Franklin52
Try this:

Code:
sed 's/\(.*THDEA\).*\(:.*\)/\1\2/'

Hey, here i'm again:
it seems in strings where there are more than one ':' after the name (in this case, AQAEO) this command eats up the line up to the last ':' in the string instead of excising the text between the name and the first occurrenc of ':' after it.

I attach the initial and the resulting files. I tried to play with the '.*' part of the command but the result's the same. U have an idea why?

Thanks in advance.

Last edited by roussine; 05-26-2009 at 07:30 PM..
# 6  
Old 05-27-2009
This command should remove everything between the given pattern and the first colon:

Code:
sed 's/\(.*THDEA\)[^:]*\(:.*\)/\1\2/'

Regards
# 7  
Old 05-26-2009
Why don't you simply replace (TAGthenwhatever: with (TAG: ?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting a part of a string

Hi, I needed to extract some specific characters from a string based on user input. For example: After the script executes the user enters the following details: Please enter the string: This is a shell script Please enter the starting position: 11 Please enter the number of characters to be... (4 Replies)
Discussion started by: ChandanN
4 Replies

2. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

3. UNIX for Dummies Questions & Answers

Print part of string

I have a file called file.txt It contains strings: ALT=someone@acme.com TO=whoever@lalalulu.com How could find and print the actual address after the = sign for any given instance? I need the command to print one of them - for example someone@acme.com But have in mind that this... (3 Replies)
Discussion started by: svetoslav_sj
3 Replies

4. Shell Programming and Scripting

Need to take one part from a string

I have a string something like "/opt/src/default.cfg" OR /opt/src/common/one This whole string stored in an array. The problem is this string is not constant and it will keep on changing as lot of strings are stored in the array and it will be look like :- case 1 /opt/src/default.cfg ... (8 Replies)
Discussion started by: Renjesh
8 Replies

5. Shell Programming and Scripting

Part of a string

Hi mates, I am doing a script in ksh. I have the following string: /opt/one/two/four/five/myFile.txt And I have a variable: echo "${variable}" -> /opt/one/two/ I would like to have just the string: four/five/myFile.txt What is the better way to do that? Thanks in... (3 Replies)
Discussion started by: gonzaloron
3 Replies

6. Shell Programming and Scripting

Delete part of string

This command: du -s /Applications/TextMate.app Returns an output like this: 65792 /Applications/TextMate.app I need to delete the space and the file path in the output leaving just the number. Thanks (2 Replies)
Discussion started by: pcwiz
2 Replies

7. Shell Programming and Scripting

Getting part of a string

Hi, I have a string assinged to a varaible as below. FILE=/var/adm/message If $FILE is the value where it stores the path of message file. I would like to extract the location of the file message as below LOCATION=/var/adm FILE may have value like /var/adm/xxxx/message ... (2 Replies)
Discussion started by: raghu.amilineni
2 Replies

8. UNIX for Dummies Questions & Answers

Printing a part of a string

hi I have the input as follows ABC =893 JKL = "jee" alias PQR = 9833 alias STUVE = "kuiue" I should be able to print as follows ABC JKL alias PQR alias STUVE Thanks Suresh (7 Replies)
Discussion started by: ssuresh1999
7 Replies

9. Shell Programming and Scripting

Need help regarding replacing a part of string

Hi all suppose i have a string "abacus sabre", i need to replace occurences 'ab' with 'cd' and i need to store this result into same string and i need to return this result from script to the calling function, where as the string is passed from calling function. i tried like this ... (1 Reply)
Discussion started by: veerapureddy
1 Replies

10. Shell Programming and Scripting

how to get the last part of a string followed by a pattern

assuming "cat" is the pattern, string (regardless length) asdadfcat4 I need to get 4 for eirtrjkkkcat678- I'd get 678 (in b-shell) Thanks in advance!!! (4 Replies)
Discussion started by: bluemoon1
4 Replies
Login or Register to Ask a Question