linux - How to delete lines starting with certain numbers in a file? -
simple question here i'm kinda stuck.
let's have file 20 lines , 4 columns. first column number (1 20).
i have other file few numbers in this
1 4 19 now, how can delete line (in first file) starting numbers in second file. main problem if sed, number 1 10, 11, 12, , on. how can right way?
thanks lot!
edit: examples
file1
1 2 b b b 3 c c c 4 d d d 5 e e e 6 f f f 7 g g g 8 h h h 9 10 j j j 11 k k k 12 l l l 13 m m m 14 n n n 15 o o o 16 p p p 17 q q q 18 r r r 19 s s s 20 t t t file2
1 4 19 the result want:
2 b b b 3 c c c 5 e e e 6 f f f 7 g g g 8 h h h 9 10 j j j 11 k k k 12 l l l 13 m m m 14 n n n 15 o o o 16 p p p 17 q q q 18 r r r 20 t t t
you can use awk this:
awk 'fnr==nr{a[$1]; next} !($1 in a)' file2 file1 2 b b b 3 c c c 5 e e e 6 f f f 7 g g g 8 h h h 9 10 j j j 11 k k k 12 l l l 13 m m m 14 n n n 15 o o o 16 p p p 17 q q q 18 r r r 20 t t t breakup of awk command:
fnr == nr { # while processing file2 a[$1] # store 1st field in array next # move next record } # while processing file1 !($1 in a) # print row file1 if 1st field not in array 'a'
Comments
Post a Comment