stripping leftmost characters from string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting stripping leftmost characters from string
# 1  
Old 11-01-2007
stripping leftmost characters from string

Hi there, if i have some strings ie



test_324423
test_242332
test_767667

but I only want the number part (the bolded bit) how do I strip the leftmost 5 characters from the output so that i will have just

324423
242332
767667

any help would be greatly appreciated
Gary
# 2  
Old 11-01-2007
Code:
[yogeshs@PS0814 htdocs]$ echo $str
test_324423
[yogeshs@PS0814 htdocs]$ echo $str | cut -d "_" -f 2
324423
[yogeshs@PS0814 htdocs]$

# 3  
Old 11-01-2007
in bash
Code:
# v=test_324423
# echo ${v#*_}
324423

# 4  
Old 11-01-2007
Quote:
Originally Posted by ghostdog74
in bash
Code:
# v=test_324423
# echo ${v#*_}
324423

This solution is also valid in ksh



Jean-Pierre.
# 5  
Old 11-01-2007
Quote:
Originally Posted by aigles
This solution is also valid in ksh
i see, thanks. I don't use ksh much.
# 6  
Old 11-02-2007
that great, thanks guys
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Stripping unwanted characters in field

I wrote myself a small little shell script to clean up a file I have issues with. In particular, I am stripping down a fully qualified host/domain name to just the hostname itself. The script works, but from a performance standpoint, it's not very fast and I will be working with large data sets. ... (4 Replies)
Discussion started by: dagamier
4 Replies

2. Shell Programming and Scripting

Checking variable with specific string and stripping number from it.

I am parsing a file and I get differnt results everytime. Sometimes I get 12s sometimes I get 54m and sometime 3h.. v1=12s or v1=54m or v1=3h 12s - 12 seconds 54m - 54 minutes 3h - 3 hour I have to write a script in such a way that it whenever v1 is in minutes, I should strip "m"... (14 Replies)
Discussion started by: jayeshpatel
14 Replies

3. Shell Programming and Scripting

Stripping of a symbol from string not working properly

Hi All, I used this code to strip-off $-symbol from string values. a="$980" b="897" a=`echo "$a" | sed 's/$/ /g'` b=`echo "$b" | sed 's/$/ /g'` echo "$a" echo "$b" but this results in the output: 80 and 897 it works when i use a='$987' b='890' (13 Replies)
Discussion started by: angie1234
13 Replies

4. Shell Programming and Scripting

Stripping characters from a file and reformatting according to another one

Dear experts, my problem is pretty tricky. I want to change a file (see attached input.txt), according to another file (help.txt). The output that is desired is in output.txt. The example is attached. Note that -dashes should not be treated specially, they are considered normal characters,... (2 Replies)
Discussion started by: TheTransporter
2 Replies

5. Shell Programming and Scripting

stripping out digits from a string with sed

i want to parse a string and only display the digits in that string... How would i accomplish this with sed command. For example. input string: " 033434343 dafasdf" output string: 03343434 Thanks (2 Replies)
Discussion started by: timmylita
2 Replies

6. Shell Programming and Scripting

Stripping characters from a variable

I'm using a shell script to get user input with this command: read UserInput I would then like to take the "UserInput" variable and strip out all of the following characters, regardless of where they appear in the variable or how many occurrences there are: \/":|<>+=;,?*@ I'm not sure... (5 Replies)
Discussion started by: nrogers64
5 Replies

7. Shell Programming and Scripting

Bash script - stripping away characters that can't be used in filenames

I want to create a temp file which is named based on a search string. The search string may contain spaces or characters that aren't supposed to be used in filenames so I want to strip those out. My thought was to use 'tr' with but the result is the opposite of what I want: $ echo "test... (5 Replies)
Discussion started by: mglenney
5 Replies

8. Shell Programming and Scripting

stripping certain characters in at the middle of a string

I am trying to strip out certain characters from a string on both (left & right) sides. For example, line=see@hear|touch, i only want to echo the "hear" part. Well i have tried this approach: line=see@hear|touch templine=${line#*@} #removed "see@" echo ${templine%%\|*} #removed... (4 Replies)
Discussion started by: mcoblefias
4 Replies

9. Shell Programming and Scripting

Stripping the spaces in a string variable

Hi , i have to strip the spaces in the string which has the following value ABC DEF i want this to appear like this ABC DEF is there any spilt method? please help.... Thanks (3 Replies)
Discussion started by: rag84dec
3 Replies

10. UNIX for Dummies Questions & Answers

Stripping a portion of string from behind!!!

Hi, How to strip a portion of a file name from behind...Say for Eg..i have a file name like aaaaa.bbbbb.Mar-17-2007 i want to remove .Mar-17-2007...is there a one line command which can give this output... Thanks Kumar (5 Replies)
Discussion started by: kumarsaravana_s
5 Replies
Login or Register to Ask a Question