I was working it with
awk, and keying on
$2 fields, but
awk would act differently depending on whether the FieldSeperator (
$match) starts the line, or had a blank before it, or didn't have a blank before it.
I'm thinking that
sed is my best choice for this particular task, but need some help. I thought that I would be able to get this with a few simple searches, and although I've seen plenty of examples to replace the entire line, I haven't been able to find what I need to do below. I would appreciate if someone is able to help me out.
I want to specify a variable (
$match) that is set to the match I want to find (
password=). This will actually be in a batch script where I will loop through various patterns.
I want to print:
- only lines containing the match. Ignore lines that do not have the match.
- print up to and including the 1st match value on the line
- if there is any value after the match, replace it with
- if there is nothing after the match, print line as is (or replace with
- case insensitive search for the match.
secret password=2345 2ndpassword=99485
nothing to see move along
end of file