Using AWK to Process Input from Multiple Files

awk ‘FNR==NR{a[$1]=$2 FS $3;next} here we handle the 1st input (file2). say, FS is space, we build an array(a) up, index is column1, value is column2 ” ” column3 the FNR==NR and next means, this part of codes work only for file2. you could man gawk check what are NR and FNR { print $0, … Read more

Printing with sed or awk a line following a matching pattern

Never use the word “pattern” in this context as it is ambiguous. Always use “string” or “regexp” (or in shell “globbing pattern”), whichever it is you really mean. See How do I find the text that matches a pattern? for more about that. The specific answer you want is: awk ‘f{print;f=0} /regexp/{f=1}’ file or specializing … Read more

How to print lines between two patterns, inclusive or exclusive (in sed, AWK or Perl)?

Print lines between PAT1 and PAT2 $ awk ‘/PAT1/,/PAT2/’ file PAT1 3 – first block 4 PAT2 PAT1 7 – second block PAT2 PAT1 10 – third block Or, using variables: awk ‘/PAT1/{flag=1} flag; /PAT2/{flag=0}’ file How does this work? /PAT1/ matches lines having this text, as well as /PAT2/ does. /PAT1/{flag=1} sets the flag … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)