ashu2888
ashu2888

Reputation: 1

linux - Seach and delete records where 2nd column starts with

"2017-09-04","D","0015","1","0015","08080000",60371,18923315.66

This is a sample record in my file abc from which I want to delete all records which are starting with 02 like -

"02080000"
"02100000"

Etc... ( Please consider " at this column start ) , I tried awk but its not working on my Linux -

awk -F"," '$6 != /^"02/' abc > abc_correct

Upvotes: 0

Views: 177

Answers (2)

Walter A
Walter A

Reputation: 20022

You can remove lines with 02 on positions 2 and 3 with

grep -vE '^.02 abc

v - skip lines
E - Expressions
^ - start of line
. - any character

Upvotes: 0

Akshay Hegde
Akshay Hegde

Reputation: 16997

Change != to !~

The two operators, ~ and !~, perform regular expression comparisons

awk -F"," '$2 !~ /^"02/' infile >outfile

For 6th column

awk -F"," '$6 !~ /^"02/' infile >outfile

May be useful:

Comparison operators in Awk are used to compare the value of numbers or strings and they include the following:

  • > – greater than
  • < – less than
  • >= – greater than or equal to
  • <= – less than or equal to
  • == – equal to
  • != – not equal to
  • some_value ~ /regexp/ – true if some_value matches regexp
  • some_value !~ /regexp/ – true if some_value does not match regexp

Upvotes: 1

Related Questions