remove characters from string based on occurrence of a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove characters from string based on occurrence of a string
# 1  
Old 02-03-2011
remove characters from string based on occurrence of a string

Hello Folks..

I need your help ..

here the example of my problem..i know its easy..i don't all the commands in unix to do this especiallly sed...here my string..

dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq

desired output is..

dwc2_dfg_ajja_dfhhj

it's a simple task with tail command, but my string size varies..only constant thing is ocuurance of this string "_vw_"

I greatly appretiate your help..

Thanks
# 2  
Old 02-03-2011
try:
Code:
sed 's/\(.*\)\(_vw_.*\)/\1/' urfile

This User Gave Thanks to yinyuemi For This Post:
# 3  
Old 02-03-2011
what's the command to get last part of the string would be..

Hello yinyuemi,

what's the command would be to get string after ocuurance of string "_vw_"

Thanks for your reply
# 4  
Old 02-03-2011
Code:
sed 's/\(.*_vw_\)\(.*\)/\2/' urfile

This User Gave Thanks to yinyuemi For This Post:
# 5  
Old 02-03-2011
Thanks Yinyuemi..

I greatly apperitiate you help
# 6  
Old 02-03-2011
Code:
$ var=dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq
$ echo ${var%%_vw_*}
dwc2_dfg_ajja_dfhhj

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Count occurrence of string (based on type) in a column using awk

Hello, I have a table that looks like what is shown below: AA BB CC XY PQ RS AA BB CC XY RS I would like the total counts depending on the set they belong to: if search pattern is in {AA, BB, CC} --> count them as Type1 | wc -l (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

2. Shell Programming and Scripting

Remove last occurrence of character (_) and rest of the string in UNIX (sed)

Hi I need help on this ..!! Input : xx_abc_regA xx_def_regB xx_qwe_regC Now i required the output as the below abc def qwe Need to remove last occurrence of character (_) and rest of the string in Unix (sed). Thanks in Advance ..!!! -Nallachand (3 Replies)
Discussion started by: Nallachand
3 Replies

3. Shell Programming and Scripting

How to remove some special characters in a string?

Hi, I have string like this ="Lookup Procedure" But i want the output like this Lookup Procedure =," should be removed. Please suggest me the solution. Regards, Madhuri (2 Replies)
Discussion started by: srimadhuri
2 Replies

4. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

5. UNIX for Dummies Questions & Answers

counting occurrence of characters in a string

Hello, I have a string like this 0:1:2:0:2:2:4:0:0:0:-200:500...... what i want is to break down how many different characters are there and their count. For example for above string it should display 0 - 5 times 1 - 1 times 2 - 3 times 4 - 1 times . . . I am stuck in writing... (8 Replies)
Discussion started by: exit86
8 Replies

6. Shell Programming and Scripting

Remove string between two special characters

Hi All, I have a variable like AVAIL="\ BACK:bkpstg:testdb3.iad.expertcity.com:backtest|\ #AUTH:authstg:testdb3.iad.expertcity.com:authiapd|\ TEST:authstg:testdb3.iad.expertcity.com:authiapd|\ " What I want to do here is that If a find # before any entry, remove the entire string... (5 Replies)
Discussion started by: engineermayur
5 Replies

7. Shell Programming and Scripting

Remove characters from string

Hi I am new in shell scripting and i want to manipulate a string. I have a string tha looks like: /home/nteath/file.txt I want to remove everything until the last "/" , to keep only the filename. e.g. /home/nteath/file.txt output: file.txt Thanks (2 Replies)
Discussion started by: nteath
2 Replies

8. Shell Programming and Scripting

remove last 4 characters from a string

I'm tring to remove the last 4 characters from strings in a file i.e. cat /tmp/test iwishicouldremovethis icouldremovethos so i would end up with the last 4 characters from each of the above i.e. this thos I thought of using cut -c ... but I'm not sure how many characters will... (7 Replies)
Discussion started by: josslate
7 Replies

9. Shell Programming and Scripting

how to remove characters from a string

Hi. for the following line: Var1=${Array} now Array has text as "{hello there}" how do I remove the {} brackets before assigning the string to Var1? Thanks. (3 Replies)
Discussion started by: shadow_boi
3 Replies

10. Shell Programming and Scripting

Remove special characters from string

Hi there, I'd like to write a script that removes any set of character from any string. The first argument would be the string, the second argument would be the characters to remove. For example: $ myscript "My name's Santiago. What's yours?" "atu" My nme's Snigo. Wh's yors? I wrote the... (11 Replies)
Discussion started by: chebarbudo
11 Replies
Login or Register to Ask a Question