Sponsored Content
Top Forums Shell Programming and Scripting With Regex Spliting the string into Alphanumeric and Numeric part Post 302124381 by ozgurgul on Saturday 30th of June 2007 09:25:23 AM
Old 06-30-2007
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.
Code:
dummy_postcode_1 = 'SL1' 
--> res_alpha = 'SL' and  res_numeric = '1' 
dummy_postcode_2 = 'S053' 
--> res_alpha = 'S' and  res_numeric = '053' 
dummy_postcode_3 = 'SO5R3' 
--> res_alpha = 'SO5R' and res_numeric = '3' 
dummy_postcode_4 = 'SO53R' 
--> res_alpha = 'SO53R' and res_numeric = ''
dummy_postcode_5 = '783652' 
--> res_alpha = '' and res_numeric = '783652' 

The logic of splitting these postcode strings is the rightmost alphanum character it seems and I could do that with the character checking but it seems to me this type of coding is a bit silly to do so.

Could you advise me how i can split them into two parts by using regex?

Thanks in advance,

Ozgur
 

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. 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

3. Shell Programming and Scripting

awk help with string spliting

Hello all, I am having a problem with awk's string split function. I have a string that has a number at the end, I am trying to remove the alpha portion of the string and just have the numeric part. Here is my code and the result: BEGIN { word = "$category121"; split(word, a, 121) print... (2 Replies)
Discussion started by: RobertSubnet
2 Replies

4. Shell Programming and Scripting

using regex to get part of a string ?

Hi there, i wonder, is it possible to use regular expressions to partially select a string? I have a bunch of server names which look like this server1z-test server2z2 server45z-primary server13z3 I want to extract up to and including the 'z' in the server name, so for example ... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

5. Shell Programming and Scripting

Spliting bash string into parts

Hello, let's say I have this string: string1="A\nB\nC D E\nFG\nH"; How can I split it so as to take every string separated with '\n' separately? For example, as for $string1, it would be split into string1_part1="A" string1_part2="B" string1_part3="C D E" string1_part4="FG"... (5 Replies)
Discussion started by: hakermania
5 Replies

6. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: keaneMB
2 Replies

7. Shell Programming and Scripting

Generate Regex numeric range with specific sub-ranges

hi all, Say i have a range like 0 - 1000 and i need to split into diffrent files the lines which are within a specific fixed sub-range. I can achieve this manually but is not scalable if the range increase. E.g cat file1.txt Response time 2 ms Response time 15 ms Response time 101... (12 Replies)
Discussion started by: varu0612
12 Replies

8. Shell Programming and Scripting

Regex to exclude numeric

Dear All, My regex is like below. Its says all the number in coloum is include. 11666 11777 11888 ^(?\: (0|11)(666|777|888))\\d+$ How to exclude all the numeric that not mentioned in above regex. Regards, (3 Replies)
Discussion started by: tpx99
3 Replies

9. Shell Programming and Scripting

Issue Spliting String in Python

I have a string like below Note: I have have a single to any number of comma "," seperated string assigned to jdbc_trgt variable. I need to split jdbc_trgt using comma(,) as the delimiter. I tried the below but it fails as i dont know how can i read each split string iterately. for... (4 Replies)
Discussion started by: mohtashims
4 Replies

10. Shell Programming and Scripting

Grep string with regex numeric characters

Hi all, I have the following entries in a file: Cause Indicators=80 90 Cause Indicators=80 90 Cause Indicators=82 90 Cause Indicators=82 90 Cause Indicators=82 90 The first 2 digits might change so I am after a sort of grep which could find any first 2 digits + the second 2,... (3 Replies)
Discussion started by: nms
3 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 09:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy