-1

I have a data file consists of strings and digit numbers with four columns as follows;

ALIC00AUS_R_20183350000.gz -4052052.705667828 4212835.982693942 -2545104.648264054
ALIC00AUS_R_20183350000.gz -4052052.702108623 4212836.006039822 -2545104.654250688
ALIC00AUS_R_20183350000.gz -4052052.694316 4212835.990059 -2545104.643113

I need to remove all lines includes 6 floating point numbers. The original size of the data file consists of several thousands of lines. The minimum floating point number is always 6 among the all numbers.

3
  • Do you want to remove only 6 floating point numbers, or also 5,4, ... floating point?
    – aborruso
    Apr 17, 2019 at 15:26
  • Could you please edit and add an example output?
    – dessert
    Apr 17, 2019 at 15:56
  • 1
    The only interpretation of your question that makes sense to me is that you want to delete lines where the floating point numbers have 6 digits after the decimal point. Is that correct? if so, should the condition be applied to any number or every number in the line? Apr 17, 2019 at 16:12

1 Answer 1

3
grep -v -E "\.[0-9]{6}\b" input.txt >output.txt

Here a visual explanation of the command: https://explainshell.com/explain?cmd=grep+-v+-E+%22%5C.%5B0-9%5D%7B6%7D%5Cb%22+input.txt+%3Eoutput.txt

And here the regex \.[0-9]{6}\b (https://regex101.com/r/bz5Dzr/1):

  • \. matches the character . literally (case sensitive)
  • Match a single character present in the list below [0-9]{6}
    • {6} Quantifier — Matches exactly 6 times
    • 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
  • \b assert position at a word boundary
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .