0

pattern will be present as a column in another file. file_1.txt

pattern1  pattern2
pattern3  pattern4
pattern5  pattern6

cat Mainfile.txt

mine line as pattern1 and pattern2
mine line2 as pattern5 and pattern6
other then that nothing should dispaly
unwanted line

final ouput_file.txt

mine line as pattern1 and pattern2
mine line2 as pattern5 and pattern6

if both the pattern present then only display the line, problem is that pattern is present in colomnwise in file_1.txt

Prince
  • 1

1 Answers1

0

this is bordering on obvious

sed -s 's:\([^ ]*\)[ ]*\([^ ]*\):/\1.*\2/p:' file_1.txt  | sed -f - -n Mainfile.txt

where

  • sed -s 's:\([^ ]*\)[ ]*\([^ ]*\):/\1.*\2/p:' file_1.txt

will give a list of sed command

/pattern1.*pattern2/p
/pattern3.*pattern4/p
/pattern5.*pattern6/p
  • sed -f - -n Mainfile.txt

where

  • -f - will use previous file (from | to -) as command file,
  • -n do no print line (unless matched)
Archemar
  • 31,554