Trimming a string based on delimiter.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Trimming a string based on delimiter.
# 1  
Old 12-16-2011
Question Trimming a string based on delimiter.

Hi,

I have a string say "
Code:
whateverCluster

".

I need everthing apart from the string "
Code:
Cluster

"

Input:

Code:
 
whateverCluster

Desired output:

Code:
 
whatever

# 2  
Old 12-16-2011
Code:
echo whateverCluster | sed "s/whateverCluster/whatever/"

# 3  
Old 12-16-2011
Error

Does not help.

Code:
whateverCluster

is an input to my script. So the string can be
Code:
anythingCluster, whateverCluster, alienCluster

So i can't hard-code the bold and underlined text below.

Code:
echo whateverCluster | sed "s/whateverCluster/whatever/"

However, I can hardcode
Code:
Cluster

Please help with a solution.
# 4  
Old 12-16-2011
Code:
[root@hostname test]# cat test.sh
#! /bin/bash
echo $1 | sed "s/$1/Cluster/"

[root@hostname test]# ./test.sh whateverCluster
Cluster

# 5  
Old 12-16-2011
Error

Quote:
Originally Posted by balajesuri
Code:
[root@hostname test]# cat test.sh
#! /bin/bash
echo $1 | sed "s/$1/Cluster/"
 
[root@hostname test]# ./test.sh whateverCluster
Cluster

I need everything else in the output except the word "Cluster". Did you get me ?
# 6  
Old 12-16-2011
Quote:
Originally Posted by mohtashims
I need everything else in the output except the word "Cluster". Did you get me ?
Code:
echo <string> | sed "s/Cluster//"

This User Gave Thanks to mobitron For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Splitting strings based on delimiter

i have a snippet from server log delimited by forward slash. /a/b/c/d/filename i need to cut until last delimiter. So desired output should look like: /a/b/c/d can you please help? Thanks in advance. (7 Replies)
Discussion started by: alpha_1
7 Replies

2. Shell Programming and Scripting

How to separate based on delimiter?

Hi, Variable=MKT1,MKT2,MKT3 and so on i am trying to seperate MKT1,MKT2,MKT3 and store each in a variable. the values in variable1 may vary. I am using bash (8 Replies)
Discussion started by: arghadeep adity
8 Replies

3. Shell Programming and Scripting

Separate string based on delimiter

Hi, for fd in $(grep "/tmp/" hello.properties)The grep gives me the below output: deploydir=/tmp/app1/dfol prodir= /tmp/hello/prop ...... Now i want to store /tmp/app1/dfol then /tmp/hello/prop in a variable so that i can check if those folders files exists or not. The delimiter would... (4 Replies)
Discussion started by: mohtashims
4 Replies

4. UNIX for Dummies Questions & Answers

awk for trimming a string up to the first, then second, then third... match

Hi ! With awk, I would need to trim a string from the beginning up to the first occurrence of "1", then from the beginning up to the second occurrence of "1", then from the beginning up to the third, then the fourth...., then the last occurrence of "1". input: 1aaa1bb1ccccccc dd1e1ffff... (7 Replies)
Discussion started by: beca123456
7 Replies

5. Shell Programming and Scripting

Trimming a string

Hi I need to trim white spaces from strings in a file. Input file is like this: 1_rrc_CatalogGroups.csv = 607 1_rrc_Sales_TopCatalogGroups.csv = 4 1_rrc_Sales_CatalogEntries_CatalogGroup_Rel.csv = 7 Need to trim space before and after = symbol. This is my script: #!/usr/bin/ksh ... (2 Replies)
Discussion started by: sukhdip
2 Replies

6. Shell Programming and Scripting

split record based on delimiter

Hi, My inputfile contains field separaer is ^. 12^inms^ 13^fakdks^ssk^s3 23^avsd^ 13^fakdks^ssk^a4 I wanted to print only 2 delimiter occurence i.e 12^inms^ 23^avsd^ (4 Replies)
Discussion started by: Jairaj
4 Replies

7. Shell Programming and Scripting

Trimming sequences based on Reference

My file looks something like this Wnat I need is to look for the Reference sequence (">Reference1") and based on the length of that sequence trim all the entries in that file. So, the rersulting file will contain all sequences with the same length, like this Thus, all sequences will keep... (5 Replies)
Discussion started by: Xterra
5 Replies

8. Shell Programming and Scripting

Trimming sequences based on specific pattern

My files look like this And I need to cut the sequences at the last "A" found in the following 'pattern' -highlighted for easier identification, the pattern is the actual file is not highlighted. The expected result should look like this Thus, all the sequences would end with AGCCCTA... (2 Replies)
Discussion started by: Xterra
2 Replies

9. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

10. Shell Programming and Scripting

Trimming a string

Hi, I am trying to find a script command that will let me trim leading and trailing space from a string. I have coded a SQL Select and sending the output to a file. Later I am parsing the file and reading each field. The problem is that each field uses the same size as the DB2 type it was defined... (2 Replies)
Discussion started by: fastgoon
2 Replies
Login or Register to Ask a Question