I have a file with lines of the form
/dev/sda4 6 Fri Apr 12 04:30:02 2019 +0100 /dumpx/DUMP4X/var/level6/55 86.53 MBand I have another file with lines of the form
/dumpx/DUMP4X/var/level6/55and I would like to find (and remove) all the lines in the first file which contain the strings in the second file. Fortunately, I can assume that both files are sorted in the same order.
to find a single entry is simple:
if $line =~ m?/dumpx/DUMP4X/var/level6/55? then do somethingbut what I want to do is to read lines from the two files in a suitable loop, picking out the matches, so I need a $regexp variable
So I write
$regexp = "m?" . <STDIN> . "?";(the second file is actually coming from a pipe)
and then I test
if $line =~ $regexp ...and if it matches, then I do the necessary stuff, and fetch the next $line and obtain the next $regexp.
But the =~ operator has been cunningly designed so that does not work. Essentially, if the RHS of =~ is a variable (my $regexp), then there is a builtin assumption that it uses '/' delimiters which, for my case, are totally unsuitable.
So how do I do this job?
In reply to Regex variables with delimiters by clerew
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |