Sponsored Content
Top Forums Shell Programming and Scripting parse a mixed alphanumeric string from within a string Post 302610763 by keaneMB on Wednesday 21st of March 2012 07:06:04 PM
Old 03-21-2012
parse a mixed alphanumeric string from within a string

Hi,
I would like to be able to parse out a substring matching a basic pattern, which is a character followed by 3 or 4 digits (for example S1234 out of a larger string). The main string would just be a filename, like Thisis__the FileName_S1234_ToParse.txt. The filename isn't fixed, but the section of text I'd like(S1234) probably is. The numbers in S1234 aren't always the same (could be S4521 or S332 or any other 3 or 4 digit combination).
I've tried various combinations of tr, awk, grep, and sed, but haven't been able to find exactly the command to do it. I'm going through a lot of files and basically just need to identify each file by that S123 label. Anyone got a quick one or two liner that would do what I need?
-- The S123 can have 3 or 4 digits and the leading S can be upper or lowercase (yay for non-standardized filenames)
-- This is running on SunOs 5.8 (only have access to the tools that came with that version of Solaris)
-- I am trying to add this in to a csh script.

Any help would be greatly appreciated!

Thanks,


Keane
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

matching alphanumeric string

how to match an alphanumeric string like the following. i have to do like the following. if the input line is the data is {clock_91b} i have to replace that with the string was ("clock_91b") i tried like $line =~ s/the data is\s+\{(+)\}/the string was \(\"$1\"\)/ which... (4 Replies)
Discussion started by: sskb
4 Replies

2. Shell Programming and Scripting

output only numbers from mixed string

it must be late because I'm sure this is an easy task with grep sed or awk string would be anything mixing numbers letters and ) ( = output I need is just the numbers... but I just can't seem to get it to work. Any tips would be great :) (10 Replies)
Discussion started by: nortypig
10 Replies

3. UNIX for Dummies Questions & Answers

AlphaNumeric String Operations

Hi :) I am writing a ksh I have a string of general format A12B3456CD78 the string is of variable length the string always ends with numbers (here it is 78.. it can be any number of digits may be 789 or just 7) before these ending numbers are alphabets (here it is CD can even be... (3 Replies)
Discussion started by: lakshmikanth
3 Replies

4. Shell Programming and Scripting

With Regex Spliting the string into Alphanumeric and Numeric part

Hi there With shell script I'm trying to split the string into two parts. One is alphanumeric part, the other one is a numeric part. dummy_postcode_1 = 'SL1' --> res_alpha = 'SL' and res_numeric = '1' dummy_postcode_2 = 'S053' --> res_alpha = 'S' and res_numeric = '053' ... (1 Reply)
Discussion started by: ozgurgul
1 Replies

5. Shell Programming and Scripting

ksh - test if string contains alphanumeric...

Okay I will let users input spaces as well :) I am having a mental block. I have done a couple of searches but havent found anything that I understand (the likes of :alpha: and awk). Basically I want to give the user an option to enter some text which will go down as a field within a flat... (3 Replies)
Discussion started by: tugger
3 Replies

6. Shell Programming and Scripting

how to parse this string

I want to get filenames from the following input. How can I parse this in bash. input data ------------------------------------------------------------------- path=/aaa/bbb/filename1;/aaa/filename2;/aaa/bbb/ccc/ddd/filename3 -------------------------------------------------------------------... (13 Replies)
Discussion started by: hcliff
13 Replies

7. Shell Programming and Scripting

how to insert space in alphanumeric string

Hi everyone, I want help to insert space between digits and letters in a alphanumeric string. INPUT TRY234TER PHY1TYR EXPECTED OUTPUT TRY 234 TER PHY 1 TYR The lines always begin with the letters and the alphabets will be a three letter combination before and after the number. The... (2 Replies)
Discussion started by: kaav06
2 Replies

8. Shell Programming and Scripting

Using awk to parse a file with mixed formats in columns

Greetings I have a file formatted like this: rhino grey weight=1003;height=231;class=heaviest;histology=9,0,0,8 bird white weight=23;height=88;class=light;histology=7,5,1,0,0 turtle green weight=40;height=9;class=light;histology=6,0,2,0... (2 Replies)
Discussion started by: Twinklefingers
2 Replies

9. UNIX for Beginners Questions & Answers

Need to compare numbers in alphanumeric string

Hi, I will be having file names like below, 1420SP1.01804 1420SP1.01805D 1420SP1.01805 1420SP1.01806D 1420SP1.01806 1420SP1.01901D 1420SP1.01901 1420SP1.01902D 1420SP1.01902 1420SP1.01903D 1420SP1.01903 1420SP1.01904 1420SP1.01905 From this, I need to list file names which is... (3 Replies)
Discussion started by: Sumanthsv
3 Replies

10. Shell Programming and Scripting

Generate a string of alphanumeric characters

Hi, I want a script of a code that will allow me to generate all possible combinations of alphanumberica characters of length 12 such that each string will contain numbers and either small or capital letters. For example a string may look like this: 123AB45cd678. (11 Replies)
Discussion started by: faizlo
11 Replies
XmParseMapping(library call)											      XmParseMapping(library call)

NAME
XmParseMapping -- Data type for a compound string parse mapping SYNOPSIS
#include <Xm/Xm.h> DESCRIPTION
XmParseMapping is an opaque data type for a parse mapping used by XmStringParseText to create a compound string. A parse mapping contains a pattern to be matched in text being parsed to create a compound string. It also contains a compound string, or a function to be invoked to provide a compound string, to be included in the compound string being created whenever the pattern is matched. An application uses a resource-style interface to specify components for an XmParseMapping. XmParseMappingCreate creates a parse mapping, using a resource-style argument list. XmParseMappingGetValues and XmParseMappingSetValues retrieve and set the components of a parse map- ping. XmParseMappingFree recovers memory used by a parse mapping. XmParseTable is an array of XmParseMapping objects. The XmNinvokeParseProc resource is a function of type XmParseProc, which is defined as follows: XmIncludeStatus (*XmParseProc) (text_in_out, text_end, type, tag, entry, pattern_length, str_include, call_data) XtPointer *text_in_out; XtPointer text_end; XmTextType type; XmStringTag tag; XmParseMapping entry; int pattern_length; XmString *str_include; XtPointer call_data; A parse procedure provides an escape mechanism for arbitrarily complex parsing. This procedure is invoked when a pattern in the input text is matched with a pattern in a parse mapping whose XmNincludeStatus is XmINVOKE. The input text is a pointer to the first byte of the pattern that was matched to trigger the call to the parse procedure. The parse proce- dure consumes as many bytes of the input string as it needs and sets the input text pointer to the following byte. It returns a compound string to be included in the compound string being constructed, and it also returns an XmIncludeStatus indicating how the returned compound string should be handled. If the parse procedure does not set the input text pointer ahead by at least one byte, the parsing routine con- tinues trying to match the input text with the patterns in the remaining parse mappings in the parse table. Otherwise, the parsing routine begins with the new input text pointer and tries to match the input text with patterns in the parse mappings starting at the beginning of the parse table. text_in_out Specifies the text being parsed. The value is a pointer to the first byte of text matching the pattern that triggered the call to the parse procedure. When the parse procedure returns, this argument is set to the position in the text where parsing should resume--that is, to the byte following the last character parsed by the parse procedure. text_end Specifies a pointer to the end of the text_in_out string. If text_end is NULL, the string is scanned until a NULL character is found. Otherwise, the string is scanned up to but not including the character whose address is text_end. type Specifies the type of text and the tag type. If a locale tag should be created, type has a value of either XmMULTIBYTE_TEXT or XmWIDECHAR_TEXT. If a charset should be created, type has a value of XmCHARSET_TEXT. tag Specifies the tag to be used in creating the result. The type of string tag created (charset or locale) depends on the text type and the passed in tag value. If the tag value is NULL and if type indicates that a charset string tag should be created, the string tag has the value that is the result of mapping XmSTRING_DEFAULT_CHARSET. If type indicates a locale string tag, the string tag has the value _MOTIF_DEFAULT_LOCALE. entry Specifies the parse mapping that triggered the call to the parse procedure. pattern_length Specifies the number of bytes in the input text, following text_in_out, that constitute the matched pattern. str_include Specifies a pointer to a compound string. The parse procedure creates a compound string to be included in the compound string being constructed. The parse procedure then returns the compound string in this argument. call_data Specifies data passed by the application to the parsing routine. The parse procedure returns an XmIncludeStatus indicating how str_include is to be included in the compound string being constructed. Fol- lowing are the possible values: XmINSERT Concatenate the result to the compound string being constructed and continue parsing. XmTERMINATE Concatenate the result to the compound string being constructed and terminate parsing. New Resources The following table defines a set of resources used by the programmer to specify data. The codes in the access column indicate if the given resource can be set at creation time (C), set by using XmParseMappingSetValues (S), retrieved by using XmParseMappingGetValues (G), or is not applicable (N/A). +-----------------------------------------------------------------------+ | | XmParseMapping Resource Set | | |Name | Class | Type | Default | Access | +-------------------+-------+-----------------+----------------+--------+ |XmNclientData | | XtPointer | NULL | CSG | +-------------------+-------+-----------------+----------------+--------+ |XmNincludeStatus | | XmIncludeStatus | XmINSERT | CSG | +-------------------+-------+-----------------+----------------+--------+ |XmNinvokeParseProc | | XmParseProc | NULL | CSG | +-------------------+-------+-----------------+----------------+--------+ |XmNpattern | | XtPointer | NULL | CSG | +-------------------+-------+-----------------+----------------+--------+ |XmNpatternType | | XmTextType | XmCHARSET_TEXT | CSG | +-------------------+-------+-----------------+----------------+--------+ |XmNsubstitute | | XmString | NULL | CSG | +-------------------+-------+-----------------+----------------+--------+ +-------------------+-------+-----------------+----------------+--------+ XmNclientData Specifies data to be used by the parse procedure. XmNincludeStatus Specifies how the result of the mapping is to be included in the compound string being constructed. Unless the value is XmIN- VOKE, the result of the mapping is the value of XmNsubstitute. Following are the possible values for XmNincludeStatus: XmINSERT Concatenate the result to the compound string being constructed and continue parsing. XmINVOKE Invoke the XmNinvokeParseProc on the text being parsed and use the returned compound string instead of XmNsubstitute as the result to be inserted into the compound string being constructed. The include status returned by the parse proce- dure (XmINSERT or XmTERMINATE) determines how the returned compound string is included. XmTERMINATE Concatenate the result to the compound string being constructed and terminate parsing. XmNinvokeParseProc Specifies the parse procedure to be invoked when XmNincludeStatus is XmINVOKE. XmNpattern Specifies a pattern to be matched in the text being parsed. This is a maximum of one character. XmNpatternType Specifies the type of the pattern that is the value of XmNpattern. Following are the possible values: o XmCHARSET_TEXT o XmMULTIBYTE_TEXT o XmWIDECHAR_TEXT XmNsubstitute Specifies the compound string to be included in the compound string being constructed when XmNincludeStatus is XmINSERT or XmTER- MINATE. RELATED
XmParseMappingCreate(3), XmParseMappingFree(3), XmParseMappingGetValues(3), XmParseMappingSetValues(3), XmParseTable(3), and XmString(3). XmParseMapping(library call)
All times are GMT -4. The time now is 03:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy