I'm writing a script that replaces a value in a file. The file is formatted as follows:
[param_one] [value]
[param_two] [value]
So, for this example, I'd like to replace the value for param_two. The value for param_two can be a one, or two-digit number. It replaces the value in file.cfg, and directs the output to new_file.cfg. $p2 is a variable passed as an arg on the command line. Here's what I have:
This code works like a charm if the value for param_two is a one-digit number and $p2 is a one or two-digit number. If the value is a two-digit number, however, my code only replaces only the first digit; which is not what I want. I want to be able to replace the value with whatever is passed for $p2. Any ideas? Thanks in advance.
I would like to do this:
replace the word "prod" with the word "special" but it may occur through the file naturally without a command, I only want it to happen when it has a specific command in front of it. The command will always look like this
<IMG,###,###,##,>prod/directory/IMG/file
... (4 Replies)
From my understanding when using regex1|regex2 the matching process tries each alternative in turn, from left to right, and the first one that succeeds is used.
When im trying to extract the name from those examples:
A) name.can.be.different.20.03.2009.boom
B)... (2 Replies)
I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly:
if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Hello,
I'd like to write a regex that transforms a German base form of a noun into one of its inflected forms, namely
I want to translate "Haus" to "Häuser"
This is what I've got:
/^(.+)$/_Umlaut( $1 )_er/
where _Umlaut( x )_ is a function operating on the noun stem captured by $1 The... (1 Reply)
Hi,
I want to validate strings in perl, the string may contains characters from a-zA-Z0-9 and symbols +-_.:/\
To validate such a string I computed a regex
if ($string =~ m/^/) {
print "valid";
} else {
print "invalid";
}
but this regex also validates strings that contain... (8 Replies)
Hi,
Could you please help me in writing a regex for the following requirement?
Let following be the string format:
abc.cdef.ghij.lm
I need to check between dots, there is atleast one character{a-z,A-Z,*}.
Eg: abc1.gt2.345j is valid, but not 123.abc.vff.gth because 123 should not be... (2 Replies)
I am looking for the proper regex to match the hostname "areagc11" of this log.... Any help would be awsome:)
Oct 25 11:08:18 areagc11 961: Oct 25 18:08:17.536 GMT: %SYS-5-CONFIG_I: Configured from console by someone onvty1 (10.156.72.97) (6 Replies)
Hi,
Have to filter out string before the last underscore in the following
input: UNIX_Solaris_59_KSH
output: UNIX_Solaris_59
dummy one but :mad:
Thanks & Regards,
Sourabh Singh Khichi (4 Replies)
Hi all, please can anyone show me how to use sed and regular expressions to achieve the following.
If a line contains a capital A followed by exactly 5 or 6 characters followed by an angled bracket then insert an asterix before the angled bracket.
So:
XCONFIGA12345<X
Becomes:
... (5 Replies)
hi
i would like to say "DATABASENAME=" to "TABLESNAME="
remove "," and press enter myconfig file
thanks (1 Reply)
Discussion started by: mnnn
1 Replies
LEARN ABOUT PLAN9
regex
regex(1F) FMLI Commands regex(1F)NAME
regex - match patterns against a string
SYNOPSIS
regex [-e] [ -v "string"] [ pattern template] ... pattern [template]
DESCRIPTION
The regex command takes a string from the standard input, and a list of pattern / template pairs, and runs regex() to compare the string
against each pattern until there is a match. When a match occurs, regex writes the corresponding template to the standard output and
returns TRUE. The last (or only) pattern does not need a template. If that is the pattern that matches the string, the function simply
returns TRUE. If no match is found, regex returns FALSE.
The argument pattern is a regular expression of the form described in regex(). In most cases, pattern should be enclosed in single quotes
to turn off special meanings of characters. Note that only the final pattern in the list may lack a template.
The argument template may contain the strings $m0 through $m9, which will be expanded to the part of pattern enclosed in ( ... )$0 through
( ... )$9 constructs (see examples below). Note that if you use this feature, you must be sure to enclose template in single quotes so
that FMLI does not expand $m0 through $m9 at parse time. This feature gives regex much of the power of cut(1), paste(1), and grep(1), and
some of the capabilities of sed(1). If there is no template, the default is $m0$m1$m2$m3$m4$m5$m6$m7$m8$m9.
OPTIONS
The following options are supported:
-e Evaluates the corresponding template and writes the result to the standard output.
-v "string" Uses string instead of the standard input to match against patterns.
EXAMPLES
Example 1: Cutting letters out of a string
To cut the 4th through 8th letters out of a string (this example will output strin and return TRUE):
`regex -v "my string is nice" '^.{3}(.{5})$0' '$m0'`
Example 2: Validating input in a form
In a form, to validate input to field 5 as an integer:
valid=`regex -v "$F5" '^[0-9]+$'`
Example 3: Translating an environment variable in a form
In a form, to translate an environment variable which contains one of the numbers 1, 2, 3, 4, 5 to the letters a, b, c, d, e:
value=`regex -v "$VAR1" 1 a 2 b 3 c 4 d 5 e '.*' 'Error'`
Note the use of the pattern '.*' to mean "anything else".
Example 4: Using backquoted expressions
In the example below, all three lines constitute a single backquoted expression. This expression, by itself, could be put in a menu defini-
tion file. Since backquoted expressions are expanded as they are parsed, and output from a backquoted expression (the cat command, in this
example) becomes part of the definition file being parsed, this expression would read /etc/passwd and make a dynamic menu of all the login
ids on the system.
`cat /etc/passwd | regex '^([^:]*)$0.*$' '
name=$m0
action=`message "$m0 is a user"`'`
DIAGNOSTICS
If none of the patterns match, regex returns FALSE, otherwise TRUE.
NOTES
Patterns and templates must often be enclosed in single quotes to turn off the special meanings of characters. Especially if you use the
$m0 through $m9 variables in the template, since FMLI will expand the variables (usually to "") before regex even sees them.
Single characters in character classes (inside []) must be listed before character ranges, otherwise they will not be recognized. For exam-
ple, [a-zA-Z_/] will not find underscores (_) or slashes (/), but [_/a-zA-Z] will.
The regular expressions accepted by regcmp differ slightly from other utilities (that is, sed, grep, awk, ed, and so forth).
regex with the -e option forces subsequent commands to be ignored. In other words, if a backquoted statement appears as follows:
`regex -e ...; command1; command2`
command1 and command2 would never be executed. However, dividing the expression into two:
`regex -e ...``command1; command2`
would yield the desired result.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO awk(1), cut(1), grep(1), paste(1), sed(1), regcmp(3C), attributes(5)SunOS 5.10 12 Jul 1999 regex(1F)