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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to get the last part of a string followed by a pattern
# 1  
Old 09-08-2007
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!!!
# 2  
Old 09-08-2007
Code:
echo "1test23string456" | sed "s/^.*[^0-9]\([0-9][0-9]*\)$/\1/"

# 3  
Old 09-08-2007
Code:
# var=eirtrjkkkcat678
# echo ${var##*cat}
678

# 4  
Old 09-08-2007
robotronic:

I can't get the digits followed "string", instead, I get "Variable syntax".
Why? Would you explain each syntax in sed- I'm a newbie & confused. It looks to me it tries to get at least two digits out of from the end of the string...
Thanks for your help!

ghostdog:
I assume that wasn't b-shell script? I got "bad substitution" running it.
Thanks
# 5  
Old 09-08-2007
Hi gentle peopel:

I think I got it all right:

echo "beginingPattern3568" | sed 's/^.*Pattern\([0-9]*\)$/\1/'

Thanks for helping, again.

bluemoon
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Taking out part of a string by matching a pattern

Hi All, My Problem is like below. I have a file which contains just one row and contains data like PO_CREATE12457888888888889SK1234567878744551111111111SK89456321145789955455555SK8888888815788852222 i want to extract SK12345678 SK89456321 SK88888888 So basically SK and next 8... (4 Replies)
Discussion started by: Asfakul Islam
4 Replies

2. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

3. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 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. 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

6. UNIX for Dummies Questions & Answers

Removing Part of a variable based on a pattern

Hi All, I am writing a script to work with files in a folder. The files are all in the following patterns (without quotes): "some filename - NxNN - the end.YYY" or "some filename - NNxNN - the end.YYY" Where N = a single number and YYY is the extension. Basically what I want... (5 Replies)
Discussion started by: sgtbobie
5 Replies

7. Shell Programming and Scripting

Replacing part of a pattern in sed

Hi I have a piece of xml that has a pattern like this <int>159</int><int>30</int> I want to find this pattern but only substitute the second part of the pattern to {rid1}. Is that possible in sed ? Thanks. ---------- Post updated at 12:10 PM ---------- Previous update was at 12:01 PM... (11 Replies)
Discussion started by: vnn
11 Replies

8. Shell Programming and Scripting

Search for a pattern in part of the line

Hi guys, I need to search for a particular pattern within the first 5 chars of the line. If the pattern is found then output the whole line. Unfortunately grep only searches the whole line For example if i am searching for aaaaa in these lines aaaaabbbbbccccc bbbbbcccccaaaaa grep... (6 Replies)
Discussion started by: pineapples
6 Replies

9. Solaris

How do i grep a pattern from part of LINE

Hi how do i grep only a part of the line from a file from all the lines. file: asdfgh 543212376 nag lkjh abhilash 543757858 How do i grep and print only 543212376 and 543757858 Can i grep something like 543* and print only that. (3 Replies)
Discussion started by: 123nagendrabhi
3 Replies

10. UNIX for Dummies Questions & Answers

vi part-pattern matching and deletion

Hi, I have a log file which shows the files which has been changed over the last week. They follow this pattern: old_file_version_number@@new_file_version_number Now I need to know how to delete from each line parts starting from @@. I would be issuing the command inside vi(m). So... (5 Replies)
Discussion started by: vino
5 Replies
Login or Register to Ask a Question