I was working it with awk
, and keying on $1
$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
masked
- if there is nothing after the match, print line as is (or replace with
empty
) - case insensitive search for the match.
infile.txt
dummy line
mypassword=123
PASSWORD=1234
secret password=2345 2ndpassword=99485
password=
nothing to see move along
end of file
Desired Output
mypassword=masked
PASSWORD=masked
secret password=masked
password=
=
?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." you can write anFS
expression that handles this.