unix - Delete lines in a file by piping search pattern into Sed -


is there anyway can delete lines in file below.

grep {searchpattern} {file} | cut -c 1-9 | sed {file}

whatever searching can occur fewer lines want delete. want search , take first 9 char , search again , delete whatever lines come in output.

my input file below .

0002206993022      enrollment status             terminated                              08/01/201412/31/9999  0003119343022      enrollment status             terminated                              05/28/201512/31/9999 0003119343009999   pay status                    n/a                                     09/10/201405/28/2015 

you can search "terminated" persons , take ids taking first 9 digits in first column. delete of records pay status or enrollment status or whatever

you want this:

awk '/terminated/{$0=substr($0, 1, 9);print "^" $0}' file | grep -vf - file 

update:

try (non gnu grep):

awk '/terminated/{$0=substr($0, 1, 9);print "^" $0}' file | grep -vf /dev/stdin file 

test:

$ cat file 0002206993022      enrollment status             terminated                              08/01/201412/31/9999  0003119343022      enrollment status             terminated                              05/28/201512/31/9999 0003119343009999   pay status                    n/a                                     09/10/201405/28/2015 1003119343009999   pay status                    n/a                                     09/10/201405/28/2015  $ awk '/terminated/{$0=substr($0, 1, 9);print "^" $0}' file | grep -vf - file 1003119343009999   pay status                    n/a                                     09/10/201405/28/2015 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -