thank you pludi , im not sure i fully understand whats going on here but at a guess
a) We are using hashes as delimiters
b)The .+/ would match more than one character except for a newline up to the first forward slash, i guess I am ok to put ^ in front of the dot to ensure we are matching against the beginning of the string ??
c) The bracket section is matching 1 or more word then slash then 1 or more words again ??? (to be honest im a little confused why this is in brackets)
d) The /?$ bit is matching against 0 or 1 instances of "/" at the end of the string .... I have changed this to /*$ just in case somebody puts more than one slash at the end
e) I really have no idea why there is a $1 in the 'substitute to' section of the statement ....what does this signify ?, I assume it must be a variable as opposed to a regex because wouldnt it replace the whole line with a number 1 ?? im very confused over how that bit works
Additionally, i tried adding a newline after the original string (\n) and your statement didnt remove it. Is it the case that I would still have to run a chomp on it afterwards or can that be integrated too ?
---------- Post updated at 02:50 PM ---------- Previous update was at 12:22 PM ----------
aha, figured it out ... the $1 is a back-reference and effectively whatever is matched between the parentheses in the "substitute-from" section, will populate the "substitute-to" section.. took me a while to get my head around but now i understand
Correct, keeps you from escaping every forward slash (First virtue of a programmer: lazyness).
Quote:
Originally Posted by hcclnoodles
b)The .+/ would match more than one character except for a newline up to the first forward slash, i guess I am ok to put ^ in front of the dot to ensure we are matching against the beginning of the string ??
Almost. '.+' means any character, one or more times, with greedy matching. Meaning "as much as possible", so for most strings you can leave the caret out.
Quote:
Originally Posted by hcclnoodles
c) The bracket section is matching 1 or more word then slash then 1 or more words again ??? (to be honest im a little confused why this is in brackets)
\w means any word character (alphanumeric + '_'), which is matched one or more times with non-greedy matching (aka 'as few as possible'), so it matches only up to the next forward slash. Repeat for the part after the slash.
Quote:
Originally Posted by hcclnoodles
d) The /?$ bit is matching against 0 or 1 instances of "/" at the end of the string .... I have changed this to /*$ just in case somebody puts more than one slash at the end
Correct
Quote:
Originally Posted by hcclnoodles
e) I really have no idea why there is a $1 in the 'substitute to' section of the statement ....what does this signify ?, I assume it must be a variable as opposed to a regex because wouldnt it replace the whole line with a number 1 ?? im very confused over how that bit works
$1 holds the contents of the first capturing group from the last regular expression. Anything between '(' and the matching ')' is a capturing group (can be nested, too). Example:
$1 would be "Hello", and $2 would be "World" (sans the quotes).
Quote:
Originally Posted by hcclnoodles
Additionally, i tried adding a newline after the original string (\n) and your statement didnt remove it. Is it the case that I would still have to run a chomp on it afterwards or can that be integrated too ?
Best bet would be chomp. It's possible to match the newline inside the regex using the 'm' and 's' switches, but my personal preference is chomp, as it's intent is more clear.
thank you for the time and effort responding my post pludi. As usual, thoroughly informative..
Not sure if you saw my edit to the post directly above your last one, but i just managed to figure out the back reference in parentheseis stuff before you posted which is great, but you have clarified the overall picture for me
thanks again
ps: im not sure what they do, but i have awarded you 50,000 bits (not sure if thats good or bad)
Hi,
Our log4j file contents look like this:
2018-11-20T00:06:58,888 INFO ql.Driver: Executing command(queryId=hive_20181120000656_49af4ad0-1d37-4312-872c-a247ed80c181): CREATE TABLE RESULTS.E7014485_ALL_HMS_CAP1
AS SELECT name,dept
from employee
Where employee='Jeff'... (4 Replies)
i have a file (where the column values are separated by ' and the text can be enclosed in ~) which contains data in form of
4461,2,~Basic:
2 Years/Unlimited Miles
Drivetrain:
Gas Engine
2 Years/Unlimited Miles
Duramax Engine
3 Years/Unlimited... (2 Replies)
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)
Below code extracts multiple field values from XML into array and prints all in one line.
perl -nle '@r=/(?: jndiName| authDataAlias| value| minConnections| maxConnections| connectionTimeout| name)="(+)/g and print join ",",$ENV{tIPnSCOPE},$ENV{pr
ovider},$ENV{impClassName},@r' server.xml
... (4 Replies)
Hi Folks,
I have two scripts that are used to start and stop services these scripts are at the location /opt/app/tre , so that start.sh internally starts the components and stop.sh internally stop all the components, now rite now if I have to stop the services then i need to go first the... (9 Replies)
Hi All
I need a small help for the below format in making a small script in Perl or Shell.
I have a file in which a single line entries are broken into three line entries.
Eg:
I have a
pen and
notebook.
All i want is to capture in a single line in a separate file.
eg: I have a pen and... (4 Replies)
Hi,
I'm using AIX(ksh shell).
> cat temp.txt
"a","b",0
"c",bc",0
"a1","b1",0
"cc","cb",1
"cc","b2",1
"bb","bc",2
I want the output as:
"a","b","c","bc","a1","b1"
"cc","cb","cc","b2"
"bb","bc"
I want to combine multiple lines into single line where third column is same.
Is... (1 Reply)
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)
Hi Everyone,
i have a string 00:44:40
so:
$tmp=~ s/://gi;
$tmp=~s/({2})({2})({2})/$1*3600+$2*60+$3/e;
the output is 2680.
Any way to combine this two lines into a single line?
Thanks (4 Replies)