linux - Scrubbing files from the shell -
my shell skills bit rusty, trying take 2 files , 'scrub' 1 other based on matching field. that's important part rest of line can different, if key field matches removed. example files pipe delimited , second field key field.
file 1 ------ acme|widg001|green|plant a|<timestamp> acme|widg102|blue|plant b|<timestamp> acme|widg002|yellow|plant a|<timestamp file 2 ------ acme|widg001|blue|plant a|<timestamp> acme|widg701|blue|plant a|<timestamp>
when scrub file 2 file 1 want resulting file contain is
new file ------ acme|widg102|blue|plant b|<timestamp> acme|widg002|yellow|plant a|<timestamp>
ideally solution allow me specify more 2 files ie scrub files 2, 3 & 4 file 1.
any assistance great!
since asked bash decided give go using bash. no external programs @ all.
ifs='|' declare -a scrub while read f1 f2 rest; scrub[$f2]=0 done < file2.txt while read f1 f2 rest; if [ ! ${scrub[$f2]} ]; echo "$f1|$f2|$rest" fi done < file1.txt
this caches values scrub first, iterates through candidates first file, printing not scrubbed. it's not pretty, it's bash.
Comments
Post a Comment