Sponsored Content
Top Forums Shell Programming and Scripting How to extract text from string using regular expressions Post 302247989 by jtung on Thursday 16th of October 2008 09:26:16 PM
Old 10-16-2008
sorry for not being more specific.

I have a file name that I want to extract the next 4 numbers after the _C
everything before and after that, I would like stripped off.

I tried using {filename:X:Y} but i don't think i'm on the latest ksh.

So i was reading up on the internet that I could use sed to accomplish this.

If there is another way to do this, please let me know.

thanks in advance!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular Expressions

I'm trying to parse RichText to XML. I want to be able to capture everything between the '/par' tag in the RTF but not include the tag itself. So far all I have is this, '.*?\\par' but it leaves '\par' at the end of it. Any suggestions? (1 Reply)
Discussion started by: AresMedia
1 Replies

2. Shell Programming and Scripting

regular expressions

Hello, Let say I have a string with content "Free 100%". How can extract only "100" using ksh? I would this machanism to work if instead of "100" there is any kind of combination of numbers(ex. "32", "1238", "1"). I want to get only the digits. I have written something like this: ... (4 Replies)
Discussion started by: whatever
4 Replies

3. Shell Programming and Scripting

Need help in string extraction using regular expressions

Hi, I am a new bee to this forum. I am trying to extract the text after a matching pattern from a url using regular expression. Ex: http://locatlhost:2020/proxy/checkthisout I want to extract the string after proxy/. I am not familiar with reg ex. Can someone please help? (2 Replies)
Discussion started by: akatraga
2 Replies

4. UNIX for Dummies Questions & Answers

Regular expressions

In regular expressions with grep(or egrep), ^ works if we want something in starting of line..but what if we write ^^^ or ^ for pattern matching??..Hope u all r familiar with regular expressions for pattern matching.. (1 Reply)
Discussion started by: aadi_uni
1 Replies

5. Shell Programming and Scripting

Regular Expressions

what elements does " /^/ " match? I did the test which indicates that it matches single lowercase character like 'a','b' etc. and '1','2' etc. But I really confused with that. Because, "/^abc/" matches strings like "abcedf" or "abcddddee". So, what does caret ^ really mean? Any response... (2 Replies)
Discussion started by: DavidHe
2 Replies

6. Shell Programming and Scripting

Regular expressions help

need a regex that matches when a number has a zero (0) at the end of it so like 10 20 120 30 330 1000 and so on (6 Replies)
Discussion started by: linuxkid
6 Replies

7. Shell Programming and Scripting

Help with regular expressions

I have a file that I'm trying to find all the cases of phone number extensions and deleting them. So input file looks like: abc x93825 def 13234 x52673 hello output looks like: abc def 13234 hello Basically delete lines that have 5 numbers following "x". I tried: x\(4) but it... (7 Replies)
Discussion started by: pxalpine
7 Replies

8. Shell Programming and Scripting

Regular Expressions

I am new to shell scripts.Can u please help me on this req. test_user = "Arun" if echo "test_user is a word" else echo "test_user is not a word" (1 Reply)
Discussion started by: chandrababu
1 Replies

9. UNIX for Dummies Questions & Answers

extract columns using grep or regular expressions

I am trying to print columns from a table whose name (header) matches a certain string. E.g., patient1001 patient1002 patient2005 patient3005 patient4001 0 0 0 0 0 2 9 2 8 3 2 7 3 0 2 Say I want to print columns whose names end with "01" patient1001 patient4001 0 0 2 3 2 2 ... (3 Replies)
Discussion started by: quextil
3 Replies

10. Shell Programming and Scripting

regular expression with shell script to extract data out of a text file

hi i am trying to extract some specific data out of a text file using regular expressions with shell script that is using a multiline grep .. and the tool i am using is pcregrep so that i can get compatibility with perl's regular expressions for a sample data like this, i am trying to grab... (6 Replies)
Discussion started by: vemkiran
6 Replies
patterns(4)						     Kernel Interfaces Manual						       patterns(4)

NAME
patterns - Patterns for use with internationalization tools SYNOPSIS
See the Description section. DESCRIPTION
The patterns file contains the patterns that must be matched for the internationalization tools extract, strextract, and strmerge. The pattern file in the following example is the default patterns file located in /usr/lib/nls/patterns. # This is the header to insert at the beginning of the first new # source file $SRCHEAD1 (1) #include <nl_types.h> nl_catd _m_catd; # The header to insert at the beginning of the rest of the new # source files $SRCHEAD2 (2) #include <nl_types.h> extern nl_catd _m_catd; # This is the header to insert at the beginning of the message # catalogues $CATHEAD (3) $ /* $ * X/OPEN message catalogue $ */ $quote " # This is how patterns that are matched will get rewritten. $REWRITE (4) catgets(_m_catd, %s, %n, %t) # Following is a list of the sort of strings we are looking for. # The regular expression syntax is based on regexp(3). $MATCH (5) # Match on strings containing an escaped " "[^\]*\"[^"]*" # Match on general strings "[^"]*" # Now reject some special C constructs. $REJECT (6) # the empty string ""0 # string with just one format descriptor "%." "%.." # string with just line control in "\." # string with just line control and one format descriptor in "%.\." "\.%." # ignore cpp include lines #[ ]*include[ ]*".*" #[ ]*ident[ ]*".*" # reject some common C functions and expressions with quoted # strings [sS][cC][cC][sS][iI][dD][][ ]*=[ ]*".*" open[ ]*([^,]*,[^)]*) creat[ ]*([^,]*,[^)]*) access[ ]*([^,]*,[^)]*) chdir[ ]*([^,]*,[^)]*) chmod[ ]*([^,]*,[^)]*) chown[ ]*([^,]*,[^)]*) # Reject any strings in single line comments /*.**/ # Print a warning for initialised strings. $ERROR initialised strings cannot be replaced (7) char[^=]*=[ ]*"[^"]*" char[^=]*=[ ]*"[^\]*\"[^"]*" char[ ]***[A-Za-z][A-Za- z0-9]*[[^]*][ ]*=[ {]*"[^"]*" char[ ]***[A-Za-z][A-Za-z0-9]*[[^]*][ ]*=[ {]*"[^\]*\"[^"]*" The default patterns file is divided into the following sections: In the $SRCHEAD1 section, the strmerge and extract commands place text in this section at the beginning of the first new source program, which is prefixed by nl_. These commands define the native language file descriptors that point to the message catalog. In the $SRCHEAD2 section, the strmerge and extract commands place text in this section at the beginning of the second and remaining source programs. These commands also define the native language file descriptors that point to the message catalog. $SRCHEAD2 contains the external declaration of the nl file descriptor. In the $CATHEAD section, the strmerge and extract commands place text in this section at the beginning of the message catalog. In the $REWRITE section, you specify how the strmerge and extract commands should replace the extracted strings in the new source program. You can supply three options to the catgets command: This option increments the set number for each source. This option applies only if you are using the strmerge command. For more informa- tion on set numbers, see the catgets(3) reference page. This option increments the message number for each string extracted. This option applies if you are using either the strmerge or extract commands. This option expands the text from the string extracted. The string can be a error message or the default string extracted and printed by the catgets command. For example, if you want an error message to appear when catgets is unable to retrieve the message from the message catalog, you would include the following line: catgets(_m_catd, %s, %n, "BAD STRING") When catgets fails, it returns the message BAD STRING. In the $MATCH section, you specify the patterns in the form of a regular expression that you want the strextract, strmerge, and extract commands to find and match. The regular expression follows the same syntax rules as defined in regexp(3) reference page. In the $REJECT section, you specify the matched strings that you do not want the strmerge and extract commands to replace in your source program. The regular expression follows the same syntax rules as defined in regexp(3) reference page. In the $ERROR section, the strextract, strmerge, and extract commands look for bad matches and notify you with a warning message. The regular expression follows the same syntax rules as defined in the regexp(3) reference page. RELATED INFORMATION
extract(1), strextract(1), strmerge(1), trans(1), regexp(3) Writing Software for the International Market delim off patterns(4)
All times are GMT -4. The time now is 12:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy