Just so I'm clear what that does...
Will that remove any consecutive "/" and replace it with only one "/" and save the input into a NEW variable, then compare
the NEW var with the original...?
Sounds like a plan to me... Cool, Thanks!
Thanks Again,
Matt
---------- Post updated at 03:49 PM ---------- Previous update was at 03:44 PM ----------
Hey Shamrock, thanks for the reply...
Bash does have a "=~" Operator... Isn't that the REGEX Operator?
From the Bash Manpage:
Quote:
An additional binary operator, =~, is available, with the same precedence as == and !=. When it is used, the string to the right of the operator is considered an extended regular expression and matched accordingly (as in regex(3)). The return value is 0 if the string matches the pattern, and 1 otherwise. If the regular expression is syntactically incorrect, the conditional expression's return value is 2. If the shell option nocasematch is enabled, the match is performed without regard to the case of alphabetic characters. Any part of the pattern may be quoted to force it to be matched as a string. Substrings matched by parenthesized subexpressions within the regular expression are saved in the array variable BASH_REMATCH. The element of BASH_REMATCH with index 0 is the portion of the string matching the entire regular expression. The element of BASH_REMATCH with index n is the portion of the string matching the nth parenthesized subexpression.
Thanks,
Matt
---------- Post updated at 04:32 PM ---------- Previous update was at 03:49 PM ----------
Hey bipinajith,
Will I get the same result with your sed command and this one below..?
Is there any real difference between yours and mine..?
Hi All,
I would like to have a script which is able to perform the below.
Print the whole row if column1 which is "0001" for the below example is the first occurrence. Subsequent "0001" occurrence will not be printed out and so on.
Can any expert help ?
Input:
0001 k= 40
0001 k= 2... (7 Replies)
I am trying to create a shell that asks the user to enter their name, and compare it to my own by saying we have the same name or saying my name and that they have a nice name too. Here is my script...
#!/bin/bash-x
echo "Enter your name".
read name
if
then
echo "My name is Adam too"... (1 Reply)
Hi there,
how can i print the first pattern occurrence in a .log file?
I want to print the filename of the first 17262?
I tried but all I can do is print all the lines with the number 17262?
I tried using awk and sed but nothing!:wall:
I just want filename!
Here´s an example:
17259... (3 Replies)
Hi,
I have a file, which contains the following log data.
I am trying to print fromt he file the following data:
I have tried using sed, but I am getting from the first pattern
Thanks for your help. (5 Replies)
Hello to all,
How would be the correct regex to match only the first occurence of
the pattern 3.*6.
I'm trying with 3.*6 trying to match only 34rrte56, but with my current regex is matching 4rrte567890123456789123powiluur56. And if I try with ?
doesn't print anything
echo... (6 Replies)
Hi,
Do anybody know how to use awk to count the pattern at specific column?
Input file
M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a
.
.
Output file
M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a 3
.
.
I plan to count how many "miR" in column 3... (2 Replies)
Hello.
In bash, is there a way to trap error "file not found" when a script call another script which is not found; then abort.
Example ( part of script running with -x option set) :
+ return 0
+ RETURN_CODE=0
+ ]
+ /root/bin/200_yast_install/00_reset_yast_install
bash:... (5 Replies)
Hi folks,
I have a file with lots of lines in a text file,i need to print the occurence number after sorting based on the first column as shown below, thanks in advance.
sam,dallas,20174
sam,houston,20175
sam,atlanta,20176
jack,raleigh,457865
jack,dc,7845
john,sacramento,4567
... (4 Replies)
Discussion started by: tech_frk
4 Replies
LEARN ABOUT REDHAT
regexp
regexp(n) Tcl Built-In Commands regexp(n)
__________________________________________________________________________________________________________________________________________________NAME
regexp - Match a regular expression against a string
SYNOPSIS
regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?
_________________________________________________________________DESCRIPTION
Determines whether the regular expression exp matches part or all of string and returns 1 if it does, 0 if it doesn't, unless -inline is
specified (see below). (Regular expression matching is described in the re_syntax reference page.)
If additional arguments are specified after string then they are treated as the names of variables in which to return information about
which part(s) of string matched exp. MatchVar will be set to the range of string that matched all of exp. The first subMatchVar will con-
tain the characters in string that matched the leftmost parenthesized subexpression within exp, the next subMatchVar will contain the char-
acters that matched the next parenthesized subexpression to the right in exp, and so on.
If the initial arguments to regexp start with - then they are treated as switches. The following switches are currently supported:
-about Instead of attempting to match the regular expression, returns a list containing information about the regular expression.
The first element of the list is a subexpression count. The second element is a list of property names that describe vari-
ous attributes of the regular expression. This switch is primarily intended for debugging purposes.
-expanded Enables use of the expanded regular expression syntax where whitespace and comments are ignored. This is the same as speci-
fying the (?x) embedded option (see METASYNTAX, below).
-indices Changes what is stored in the subMatchVars. Instead of storing the matching characters from string, each variable will con-
tain a list of two decimal strings giving the indices in string of the first and last characters in the matching range of
characters.
-line Enables newline-sensitive matching. By default, newline is a completely ordinary character with no special meaning. With
this flag, `[^' bracket expressions and `.' never match newline, `^' matches an empty string after any newline in addition
to its normal function, and `$' matches an empty string before any newline in addition to its normal function. This flag is
equivalent to specifying both -linestop and -lineanchor, or the (?n) embedded option (see METASYNTAX, below).
-linestop Changes the behavior of `[^' bracket expressions and `.' so that they stop at newlines. This is the same as specifying the
(?p) embedded option (see METASYNTAX, below).
-lineanchor Changes the behavior of `^' and `$' (the ``anchors'') so they match the beginning and end of a line respectively. This is
the same as specifying the (?w) embedded option (see METASYNTAX, below).
-nocase Causes upper-case characters in string to be treated as lower case during the matching process. |
-all |
Causes the regular expression to be matched as many times as possible in the string, returning the total number of matches |
found. If this is specified with match variables, they will continue information for the last match only. |
-inline |
Causes the command to return, as a list, the data that would otherwise be placed in match variables. When using -inline, |
match variables may not be specified. If used with -all, the list will be concatenated at each iteration, such that a flat |
list is always returned. For each match iteration, the command will append the overall match data, plus one element for |
each subexpression in the regular expression. Examples are: |
regexp -inline -- {w(w)} " inlined " |
=> {in n} |
regexp -all -inline -- {w(w)} " inlined " |
=> {in n li i ne e} |
-start index |
Specifies a character index offset into the string to start matching the regular expression at. When using this switch, `^' |
will not match the beginning of the line, and A will still match the start of the string at index. If -indices is speci- |
fied, the indices will be indexed starting from the absolute beginning of the input string. index will be constrained to |
the bounds of the input string.
-- Marks the end of switches. The argument following this one will be treated as exp even if it starts with a -.
If there are more subMatchVar's than parenthesized subexpressions within exp, or if a particular subexpression in exp doesn't match the
string (e.g. because it was in a portion of the expression that wasn't matched), then the corresponding subMatchVar will be set to ``-1
-1'' if -indices has been specified or to an empty string otherwise.
SEE ALSO
re_syntax(n), regsub(n)
KEYWORDS
match, regular expression, string
Tcl 8.3 regexp(n)