Sponsored Content
Top Forums Shell Programming and Scripting Sed only digits not in numbers Post 302564013 by jejeking on Wednesday 12th of October 2011 03:11:19 PM
Old 10-12-2011
Sed only digits not in numbers

Hi,

I have a text file with an array of numbers such as :

Code:
123    1    456   45   9817   1   45

I would like to replace the digit "1" in a text file with "A". So it looks like this:
Code:
123   A   456   45   9817  A  45

If I use sed 's/1/A/g', I get

Code:
A23   A   456  45  98A7  A 45

I tried several combination such as [ 1 ] and others, to no avail.
What do I need to add to get the wanted result?
Thanks a lot!

Last edited by radoulov; 10-12-2011 at 04:13 PM.. Reason: Code tags!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed: removing any and all trailing digits?

We have a large number of oracle database related scripts that utilize the environment variables $ORACLE_SID and $DBNAME. In a single instance database the $ORACLE_SID is the same as the database name $DBNAME. So we have simply set DBNAME = $ORACLE_SID. However, now that we are clustering with RAC,... (5 Replies)
Discussion started by: Squeakygoose
5 Replies

2. Shell Programming and Scripting

help: single digits inflated to 2 digits

Hi Folks Probably an easy one here but how do I get a sequence to get used as mentioned. For example in the following I want to automatically create files that have a 2 digit number at the end of their names: m@pyhead:~$ for x in $(seq 00 10); do touch file_$x; done m@pyhead:~$ ls file*... (2 Replies)
Discussion started by: amadain
2 Replies

3. Shell Programming and Scripting

stripping out digits from a string with sed

i want to parse a string and only display the digits in that string... How would i accomplish this with sed command. For example. input string: " 033434343 dafasdf" output string: 03343434 Thanks (2 Replies)
Discussion started by: timmylita
2 Replies

4. Shell Programming and Scripting

Find filenames with three digits and add zeros to make five digits

Hello all! I've looked all over the internet and this site and have come up a loss with an easy way to make a bash script to do what I want to do. I have a file with a naming convention as follows: 2012-01-18 string of words here 123.jpg 2012-01-18 string of words here 1234.jpg 2012-01-18... (2 Replies)
Discussion started by: Buzzman25
2 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. UNIX for Dummies Questions & Answers

Grep lines with numbers greater than 2 digits at the end of the line

I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file ---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Discussion started by: jimmyf
1 Replies

7. UNIX for Dummies Questions & Answers

Replacing digits using sed

How to replace a character followed by a digit using sed? For example lets say I have this file - a1 3242134 54235435 3241235 a2 3214345 45325626 3125435 a3 4236577 54365376 6865678 . . . a3000 5432534 32546546 3254365 I want to replace all... (6 Replies)
Discussion started by: saleheen
6 Replies

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

9. UNIX for Beginners Questions & Answers

Using sed or awk to replace digits in files

Hello; I am not good at file and stream editing. I need to replace a few digits in two files. The lines in files looks like this: Line in the first file, /dw300/data/obe/2019273.L800JR.1909.273 Line in second file, 1|2019273.L800JR.1909.273 I will write a function to connect to... (7 Replies)
Discussion started by: duke0001
7 Replies

10. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies
Regexp::Common::number(3pm)				User Contributed Perl Documentation			       Regexp::Common::number(3pm)

NAME
Regexp::Common::number -- provide regexes for numbers SYNOPSIS
use Regexp::Common qw /number/; while (<>) { /^$RE{num}{int}$/ and print "Integer "; /^$RE{num}{real}$/ and print "Real "; /^$RE{num}{real}{-base => 16}$/ and print "Hexadecimal real "; } DESCRIPTION
Please consult the manual of Regexp::Common for a general description of the works of this interface. Do not use this module directly, but load it via Regexp::Common. $RE{num}{int}{-base}{-sep}{-group}{-places} Returns a pattern that matches an integer. If "-base => B" is specified, the integer is in base B, with "2 <= B <= 36". For bases larger than 10, upper case letters are used. The default base is 10. If "-sep => P" is specified, the pattern P is required as a grouping marker within the number. If this option is not given, no grouping marker is used. If "-group => N" is specified, digits between grouping markers must be grouped in sequences of exactly N digits. The default value of N is 3. If "-group => N,M" is specified, digits between grouping markers must be grouped in sequences of at least N digits, and at most M digits. This option is ignored unless the "-sep" option is used. If "-places => N" is specified, the integer recognized must be exactly N digits wide. If "-places => N,M" is specified, the integer must be at least N wide, and at most M characters. There is no default, which means that integers are unlimited in size. This option is ignored if the "-sep" option is used. For example: $RE{num}{int} # match 1234567 $RE{num}{int}{-sep=>','} # match 1,234,567 $RE{num}{int}{-sep=>',?'} # match 1234567 or 1,234,567 $RE{num}{int}{-sep=>'.'}{-group=>4} # match 1.2345.6789 Under "-keep" (see Regexp::Common): $1 captures the entire number $2 captures the optional sign of the number $3 captures the complete set of digits $RE{num}{real}{-base}{-radix}{-places}{-sep}{-group}{-expon} Returns a pattern that matches a floating-point number. If "-base=N" is specified, the number is assumed to be in that base (with A..Z representing the digits for 11..36). By default, the base is 10. If "-radix=P" is specified, the pattern P is used as the radix point for the number (i.e. the "decimal point" in base 10). The default is "qr/[.]/". If "-places=N" is specified, the number is assumed to have exactly N places after the radix point. If "-places=M,N" is specified, the number is assumed to have between M and N places after the radix point. By default, the number of places is unrestricted. If "-sep=P" specified, the pattern P is required as a grouping marker within the pre-radix section of the number. By default, no separator is allowed. If "-group=N" is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3. If "-expon=P" is specified, the pattern P is used as the exponential marker. The default value of P is "qr/[Ee]/". For example: $RE{num}{real} # matches 123.456 or -0.1234567 $RE{num}{real}{-places=>2} # matches 123.45 or -0.12 $RE{num}{real}{-places=>'0,3'} # matches 123.456 or 0 or 9.8 $RE{num}{real}{-sep=>'[,.]?'} # matches 123,456 or 123.456 $RE{num}{real}{-base=>3'} # matches 121.102 Under "-keep": $1 captures the entire match $2 captures the optional sign of the number $3 captures the complete mantissa $4 captures the whole number portion of the mantissa $5 captures the radix point $6 captures the fractional portion of the mantissa $7 captures the optional exponent marker $8 captures the entire exponent value $9 captures the optional sign of the exponent $10 captures the digits of the exponent $RE{num}{dec}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>10}{...} $RE{num}{oct}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>8}{...} $RE{num}{bin}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>2}{...} $RE{num}{hex}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>16}{...} $RE{num}{decimal}{-base}{-radix}{-places}{-sep}{-group} The same as $RE{num}{real}, except that an exponent isn't allowed. Hence, this returns a pattern matching decimal numbers. If "-base=N" is specified, the number is assumed to be in that base (with A..Z representing the digits for 11..36). By default, the base is 10. If "-radix=P" is specified, the pattern P is used as the radix point for the number (i.e. the "decimal point" in base 10). The default is "qr/[.]/". If "-places=N" is specified, the number is assumed to have exactly N places after the radix point. If "-places=M,N" is specified, the number is assumed to have between M and N places after the radix point. By default, the number of places is unrestricted. If "-sep=P" specified, the pattern P is required as a grouping marker within the pre-radix section of the number. By default, no separator is allowed. If "-group=N" is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3. For example: $RE{num}{decimal} # matches 123.456 or -0.1234567 $RE{num}{decimal}{-places=>2} # matches 123.45 or -0.12 $RE{num}{decimal}{-places=>'0,3'} # matches 123.456 or 0 or 9.8 $RE{num}{decimal}{-sep=>'[,.]?'} # matches 123,456 or 123.456 $RE{num}{decimal}{-base=>3'} # matches 121.102 Under "-keep": $1 captures the entire match $2 captures the optional sign of the number $3 captures the complete mantissa $4 captures the whole number portion of the mantissa $5 captures the radix point $6 captures the fractional portion of the mantissa $RE{num}{square} Returns a pattern that matches a (decimal) square. Because Perl's arithmetic is lossy when using integers over about 53 bits, this pattern only recognizes numbers less than 9000000000000000, if one uses a Perl that is configured to use 64 bit integers. Otherwise, the limit is 2147483647. These restrictions were introduced in versions 2.116 and 2.117 of Regexp::Common. Regardless whether "-keep" was set, the matched number will be returned in $1. This pattern is available for version 5.008 and up. $RE{num}{roman} Returns a pattern that matches an integer written in Roman numbers. Case doesn't matter. Only the more modern style, that is, no more than three repetitions of a letter, is recognized. The largest number matched is MMMCMXCIX, or 3999. Larger numbers cannot be expressed using ASCII characters. A future version will be able to deal with the Unicode symbols to match larger Roman numbers. Under "-keep", the number will be captured in $1. SEE ALSO
Regexp::Common for a general description of how to use this interface. AUTHOR
Damian Conway (damian@conway.org) MAINTAINANCE
This package is maintained by Abigail (regexp-common@abigail.be). BUGS AND IRRITATIONS
Bound to be plenty. For a start, there are many common regexes missing. Send them in to regexp-common@abigail.be. LICENSE and COPYRIGHT This software is Copyright (c) 2001 - 2009, Damian Conway and Abigail. This module is free software, and maybe used under any of the following licenses: 1) The Perl Artistic License. See the file COPYRIGHT.AL. 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2. 3) The BSD Licence. See the file COPYRIGHT.BSD. 4) The MIT Licence. See the file COPYRIGHT.MIT. perl v5.14.2 2011-04-16 Regexp::Common::number(3pm)
All times are GMT -4. The time now is 09:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy