Need help to use regex to do search and replace. Don't know how to and can't figure out how :(
Hi,
Below is an excerpt from a 20000+ lines and I want to do a search and replace of a specific string but I don't know how and I can't figure out how to. Can't find an example from Google or anywhere to do what I am wanting to do.
I need to search for all lines that contain the string /db/LTS/abcp_ but only those that ends in .dbf. So from the excerpts above, it should find the line below:
And I want to replace them so it so that it will be
So, basically I need to change /db/LTS/abcp_ to /db/LTS/abct_. It is the one in BOLD that I am wanting to search and replace.
The grep regex below seems to do what I wanted. But I don't know how to do like a sed search and replace thing
Any help will be much appreciated.
P.S.:
- Is there any way to colorize or highlight certain text? I was hoping to be able to do that in this post but can't find the option to do so. I thought that option was available on the older forum ???
And, yes, the text colour selector (available in the "quick reply editor") seems to be missing in the "advanced editor". But with the bold and underline you did quite well.
Doesn't work on Solaris but works perfectly on Linux. Thanks a lot. Not even our supposedly 'smartest' SA can figure out what to do. You're a genius.
Sorry forgot to say am trying to do this on Solaris. I have to do the sed on Linux and copy the file back to Solaris. Any idea how to go on the Solaris 8/10?
Can't quite work out or understand 100% what your code does though? Do you mind providing answers to my questions?
01 - Why are you escaping the # in the beginning?
02 - The p before the (_ is because I want to match a single p? Is that correct?
03 - The #s//\1t\2/ is the one that I don't understand for the most part. Is it doing another search?
The following seems to do what you want just using standard sed features:
The \1 and \2 in the replacement string in the substitute command are back references that are replaced by the strings matched by the BREs between the escaped sets of parentheses, respectively.
Using unescaped parentheses (as in RudiC's suggestion) is a GNU extension that is not allowed in the standards. The sed -r option is not included in the standards, but is allowed as an extension.
When I was using Solaris systems, I would have done this using /usr/xpg4/bin/sed, but I don't think there is anything in the above commands that won't work with /bin/sed or /usr/bin/sed.
These 3 Users Gave Thanks to Don Cragun For This Post:
Have Pipe Delimited File:
> BRYAN BAKER|4/4/2015|518 VIRGINIA AVE|TEST
> JOE BAXTER|3/30/2015|2233 MockingBird RD|ROW2On 3rd column where the address is located, I want to add a space after every numeric value - basically doing a "s//&\ / ":
> BRYAN BAKER|4/4/2015|5 1 8 VIRGINIA AVE|TEST
> JOE... (5 Replies)
Basically what the title says. Had to replace the motherboard on an HP DL380 G6 today, of course now the embedded NICs don't work because the ifcfg-eth files have the MAC addresses for the embedded NICs from the old machine.
How can I find the new/correct MAC addresses so I can edit the... (2 Replies)
I have file which contains data in the following format all in a single line:
BDW_PUBLN_ID DECIMAL(18:0) NOT NULL PRIMARY INDEX ARGO_ACCT_DEP_PI ( OFC_ID ,CSHBX_ID ,TRXN_SEQ_NUM ,PROCG_DT ) PARTITION BY RANGE_N(PROCG_DT BETWEEN DATE '2012-03-01' AND DATE '2014-12-31' EACH INTERVAL '1' MONTH );... (4 Replies)
Hi,
I'm trying to match the front and back of a sequence. It works when there is an exact match (obviously), but I need the regex to be more flexible. When we get strings of nucleotides sometimes their prefixes and suffixes aren't exact matches. Sometimes there will be an extra letter and... (2 Replies)
Hi,
I need to run a search and replace on a large database,
what I need to change is all instances of
#### (eg. 1764 or 1964)
to
(####) (eg. (1764) or (1964))
But there might be other numbers in there such as
(1764) and I do not need those changed to ((1764))
How can I... (7 Replies)
Hi guys, I asked for help on programming forums and no one didn't helped me so I ask for help here. I am playing with some tasks from my book and I can't figure where did I get wrong.
From the first program I get a blank screen, program won't generate 10*10 matrix.
And second problem is I... (6 Replies)
Thanks for giving your time and effort to answer questions and helping newbies like me understand awk.
I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk.
Basically I'd like all lines with ISA sandwiched between... (9 Replies)