Reputation: 32316
I have a text file with tab delimited data spread across 16 columns. I want to delete the complete row where the values 1260, 1068 and 907 found in 6th column.
9513 2010-06-15 17:00:00 94 0 69 12 0 0 0 0.0000 0 \N \N \N 2010-06-15 18:00:02 \N
9523 2010-06-15 18:00:00 94 0 69 12 0 0 0 0.0000 0 \N \N \N 2010-06-15 19:00:02 \N
9534 2010-06-15 19:00:00 94 0 69 12 0 0 0 0.0000 0 \N \N \N 2010-06-15 20:00:02 \N
9543 2010-06-15 20:00:00 94 0 69 12 0 0 0 0.0000 0 \N \N \N 2010-06-15 21:00:02 \N
9552 2010-06-15 21:00:00 94 0 69 12 0 0 0 0.0000 0 \N \N \N 2010-06-15 22:00:02 \N
9560 2010-06-15 22:00:00 94 0 69 12 0 0 0 0.0000 0 \N \N \N 2010-06-15 23:00:02 \N
9569 2010-06-15 23:00:00 94 0 69 12 0 0 0 0.0000 0 \N \N \N 2010-06-16 00:00:02 \N
9579 2010-06-16 00:00:00 94 0 69 12 0 0 0 0.0000 0 \N \N \N 2010-06-16 01:00:02 \N
9589 2010-06-16 01:00:00 94 0 69 12 0 0 0 0.0000 0 \N \N \N 2010-06-16 02:00:01 \N
9599 2010-06-16 02:00:00 94 0 69 12 0 0 0 0.0000 0 \N \N \N 2010-06-16 03:00:02 \N
95642733 2011-10-19 19:00:00 4341 0 1263 0 11 0 0 0.0000 0 \N \N \N 2011-10-19 20:05:06 \N
95642732 2011-10-19 19:00:00 4341 0 1260 0 24635 0 0 0.0000 0 \N \N \N 2011-10-19 20:05:06 \N
95642540 2011-10-19 19:00:00 4050 0 1068 103 113 2 0 0.0000 0 \N \N \N 2011-10-19 20:05:06 \N
95642539 2011-10-19 19:00:00 4050 0 907 19 0 0 0 0.0000 0 \N \N \N 2011-10-19 20:05:06 \N
Upvotes: 0
Views: 275
Reputation: 58420
This might work for you (GNU sed?):
sed '/^\(\S*\s*\)\{5\}\(1260\|1068\|907\)\s/d' file
or generally:
sed '/^\([^[:space:]]*[[:space:]]*\)\{5\}\(1260\|1068\|907\)[[:space:]]/!d'
Upvotes: 0
Reputation: 6551
What you want to us is awk. Awk is an amazingly powerful language inside UNIX, and if you ever run into a complicated test-streaming problem, awk is your solution.
Try this script:
awk '{
if ($6 != 1260 || $6 != 1068 || $6 != 907)
print $0;
}' file.txt >> output_file.txt
Upvotes: 0
Reputation: 46846
Awk is the tool you want to use.
awk '$6==1260 || $6==1068 || $6==907 {next} {print}'
What does this do?
Awk runs a block of code on each line of your file. The code starts with an expression that must evaluate true (in this case the three possible values of the 6th field), followed by commands in curly braces. In this case, the command next
tells it to proceed to the next input line without running any more commands.
If the three comparisons FAIL, and we don't run the next
, then we print the line.
Upvotes: 4