Issue
Is there anyway we can delete lines in a file like below.
grep {SearchPattern} {file} | cut -c 1-9 | Sed {file}
Whatever I am searching can actually occur fewer than lines I want to delete. I want to actually search and take first 9 char and search again and delete whatever lines come in output.
my input file would like as 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 I would to search for all "Terminated" persons and take their IDs by taking first 9 digits in the first column. I would like to delete all of their records be it Pay Status or Enrollment Status or whatever
Solution
You want something like 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
Answered By - sat