regex to match digits not in dates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting regex to match digits not in dates
# 1  
Old 03-20-2011
regex to match digits not in dates

hi all, im having problems. I need to change all number 10 in a text file to word form, or in short from 10->ten. the thing is number 10 including in dates such as 10/22/1997 or 03-10-2011 should not be changed. im having some trouble because the file contains numbers like "price range from 10-50k". can someone come up with a regex that will match this kind of thing thanks..
# 2  
Old 03-20-2011
You have to provide us with what should be changed to what. Preferably show us sample of your file, with all the cases that you might deal with, and how it should look like after processing.
# 3  
Old 03-20-2011
this is just a sample.
Code:
name: john smith
birthday: 10-11-1995
date hired: 05/10/2010
expected salary: 10-50k
typing speed: 10 wpm
coordinates: (10, 10)

should come out like this:
Code:
name: john smith
birthday: 10-11-1995
date hired: 05/10/2010
expected salary: ten-50k
typing speed: ten wpm
coordinates: (ten, ten)

hope this could help

Last edited by Franklin52; 03-21-2011 at 04:57 AM.. Reason: Please use code tags
# 4  
Old 03-20-2011
Try:
Code:
perl -pe '!/\d\d-\d\d-\d{4}/ && s/10/ten/g' file

# 5  
Old 03-20-2011
thanks ill try it

---------- Post updated at 12:30 AM ---------- Previous update was at 12:16 AM ----------

$lines[$i]=~!/\d\d-\d\d-\d{4}/ && s/10/ten/g;
i used this line but its not working maybe theres something wrong. Maybe the && only works in shell
# 6  
Old 03-20-2011
Post full code that you are using.
# 7  
Old 03-20-2011
Hi ,

Use this code!!

Code:
sed -E '/day|date/ !s/10/ten/g' file

or

Code:
sed -r '/day|date/ !s/10/ten/g' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

2. UNIX for Dummies Questions & Answers

Determine if first 2 digits of string match numbers

Trying to find out how to discover if the first 2 characters of a string are "22" Not sure how. I could use if ]; then echo "yes";fi But I think that will only grab the pattern 22 and not the first 2 digits. (5 Replies)
Discussion started by: newbie2010
5 Replies

3. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

4. Shell Programming and Scripting

Regex find first 5-7 occurrences of a set of digits within a string

Using these strings as an example: <a onclick="doShowCHys=1;ShowWindowN(0,'/daman/man.php?asv4=145148&amp;playTogether=True',960,540,943437);return false;" title=""> <a onclick="doShowCHys=1;ShowWindowN(0,'/daman/man.php?asv4=1451486&amp;playTogether=True',960,540,94343);return false;" title=""> <a... (12 Replies)
Discussion started by: metallica1973
12 Replies

5. Shell Programming and Scripting

Regex - Return numbers of exactly 8 digits

Hi All I am new to this forum and also regex. I am using bash scripting and have a file like this "0012","efgh","12345678","adfdf", "36598745" "87654321","hijk","lmno" I want the ouput to be 12345678 36598745 87654321 Criteria like this - number - 8 carachters long Please let... (21 Replies)
Discussion started by: buttseire
21 Replies

6. Shell Programming and Scripting

Use match() in nawk to find digits in number

Hi, I just need to check whether number of digits in a phone number is 10 or not. If I am not wrong regex will be: {9} I have to use this inside nawk as this is a small portion of a big program. nawk ' BEGIN { RS="";FS=";"; regex="{9}"; } { for (i=1;i<=NF;i++) { if... (6 Replies)
Discussion started by: shekhar2010us
6 Replies

7. UNIX for Advanced & Expert Users

Regex pattern for multiple digits

Hello, I need to construct a pattern to match the below string (especially the timestamp at the beginning) 20101222100436_temp.dat The below pattern works _temp.dat However I am trying find if there are any other better representations. I tried {14}, but it did not work. I am on... (5 Replies)
Discussion started by: krishmaths
5 Replies

8. UNIX for Advanced & Expert Users

Regex to match IP address

What do you think of this regex to match IP address? I have been reading up on regex and have seen some really long ones for IP. Would this fail in any scenarios? (+\.){3}* (5 Replies)
Discussion started by: glev2005
5 Replies

9. Shell Programming and Scripting

How to pattern match on digits and then increment?

I have a log file that ends in a ".xxx" where xxx are digits but I don't necessarily know what digits they are. The log file rotates automatically and is auto-incrementing - starting at .001. So the example would be: file-name.005 If the file ends in .005 and the log rotates, it logically... (2 Replies)
Discussion started by: sdutto01
2 Replies

10. UNIX for Dummies Questions & Answers

match dates

Hi all, Does anybody know how the command to compare today's date with a unix file's date? (3 Replies)
Discussion started by: poohxiong
3 Replies
Login or Register to Ask a Question