context: grep for multiple strings in file on different lines (ie. whole file, not line based search)?
egrep -nH 'Dansk|Norsk|Svenska' file3
or using ripgrep
rg 'Dansk|Norsk|Svenska' file3
But there is an answer
awk '/Dansk/{a=1}/Norsk/{b=1}/Svenska/{c=1}END{ if (a && b && c) print $0 }' file3
I don't understand this answer.
I understand awk '/Dansk/{a=1}/Norsk/{b=1}/Svenska/{c=1}
.
I think now the question is using awk, while pattern matched, print line number with output lines.
update:
I even understand this answer.
update:
almost close:
awk '/Dansk/{a=1}/Norsk/{b=1}/Svenska/{c=1}{ if (a || b || c ) print $0; next}1' file3
it return
Subtitle: 04, Language: da - Dansk, Content: Undefined, Stream id: 0x23,
Subtitle: 05, Language: de - Deutsch, Content: Undefined, Stream id: 0x24,
the expected return is
Subtitle: 04, Language: da - Dansk, Content: Undefined, Stream id: 0x23,
file3
content:
Disc Title: unknown
Title: 01, Length: 01:33:37.000 Chapters: 33, Cells: 31, Audio streams: 04, Subpictures: 20
Subtitle: 01, Language: ar - Arabic, Content: Undefined, Stream id: 0x20,
Subtitle: 02, Language: bg - Bulgarian, Content: Undefined, Stream id: 0x21,
Subtitle: 03, Language: cs - Czech, Content: Undefined, Stream id: 0x22,
Subtitle: 04, Language: da - Dansk, Content: Undefined, Stream id: 0x23,
Subtitle: 05, Language: de - Deutsch, Content: Undefined, Stream id: 0x24,
(...)
update. almost close.
awk '/Dansk/{a=1}/Norsk/{b=1}/Svenska/{c=1}{ if (a || b || c ) print NR, $0}' file3
But it returns
6 Subtitle: 04, Language: da - Dansk, Content: Undefined, Stream id: 0x23,
7 Subtitle: 05, Language: de - Deutsch, Content: Undefined, Stream id: 0x24,
8 (...)
x||y||z||...
means "if x OR y OR z OR ... were True" then do something.x&&y&&z&&...
means "if x AND y AND z AND ... all were True" then do something."True" means a result of an expression or condition evaluated true. I believe you strongly need to start first reading some basics of awk commnad.rg 'Dansk|Norsk|Svenska' file3
command which return ` Subtitle: 04, Language: da - Dansk, Content: Undefined, Stream id: 0x23,` but now myawk
idea return the matched line and the next line. I only want matched line. now I don't know how to improve it.awk '/Dansk/{a=1}/Norsk/{b=1}/Svenska/{c=1}{ if (a || b || c ) print NR, $0}'
you can just doawk '/Dansk|Norsk|Svenska/{print NR, $0}'
, but I really don't know what are you trying to do here at all. what is your question and goal now?