2

I have a large text file on a Linux server containing the following, for example:

123456789012345,00,0000,0000
1234567890123450,00,0000,000
12345678901b111,0,0000,0000
1234567/89011111,00,0000,00000

OUTPUT

12345678901b111,0,0000,0000       line# 3
1234567/8011111?,00,0000,00000    line# 4

so my target is:

I would like to grep lines which is

not 15 or 16 digits only before first comma
not 2 digits only before second comma
not 3 or 4 digits only before third comma
not 3 or 4 digits only after third comma

**the line should cover ANY of the predefined conditions**

with printing line number for each line and save to another text.

  • your output does not fit 2 requirements not 2 digits only before second comma and not 3 or 4 digits only after third comma . Update your question – RomanPerekhrest Nov 15 '17 at 15:47
  • @RomanPerekhrest welcome :) king long time i didn't see ya, hope you ok. looks like you misunderstood me. i want to grep only if condition applied. so if it's not 2 digits before second comma and not 3 or 4 digits after third comma so i want to grep it as my output show – αԋɱҽԃ αмєяιcαη Nov 15 '17 at 15:48
  • again, the condition not 2 digits only before second comma does not cover the 2nd line 1234567/8011111?,00,0000,0000 from your output. Make your conditions more clear – RomanPerekhrest Nov 15 '17 at 15:50
  • yes but it's cover the first condition which is "not 15 or 16 digits only before first comma" – αԋɱҽԃ αмєяιcαη Nov 15 '17 at 15:51
  • Then, you must have been specified in your question that the line should cover ANY of the predefined conditions. Just do a proper formulations – RomanPerekhrest Nov 15 '17 at 15:52
2

AWK solution:

awk -F, '$1!~/[0-9]{15,16}/ || $2!~/[0-9]{2}/ || $3!~/[0-9]{3,4}/ || $4!~/[0-9]{3,4}/{ 
             printf "%-35s line# %s\n",$0,NR 
         }' file
  • -F, - treating comma , as field separator

  • printf "%-35s line# %s\n" - aligned/arranged formatted output


The output:

12345678901b111,0,0000,0000         line# 3
1234567/89011111,00,0000,00000      line# 4
  • I have edit my question in order to print the output with line number – αԋɱҽԃ αмєяιcαη Nov 15 '17 at 16:13
  • @αԋɱҽԃαмєяιcαη, ok, see my update – RomanPerekhrest Nov 15 '17 at 16:20
  • 1
    AWESOME !! BIG MILLION THANKS FOR YOU THAT YOU SAVED MY TIME – αԋɱҽԃ αмєяιcαη Nov 15 '17 at 16:22
  • @αԋɱҽԃαмєяιcαη, you're welcome, glad to help – RomanPerekhrest Nov 15 '17 at 16:36
  • based on the same example, how can i print lines which is 4 digits after last comma – αԋɱҽԃ αмєяιcαη Nov 27 '17 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.