report if any one record is not of matching size using sed [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-3
down vote

favorite












how can I use sed to report any first record that is not of size 21 in a file?



I don't want sed to scan the complete file and get out as soon as the first record which is not of size 21 is found.







share|improve this question













closed as unclear what you're asking by DopeGhoti, steve, G-Man, dr01, X Tian May 17 at 15:59


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • i have the sed command i am not sure how to break out of it .
    – Ahmad S
    May 16 at 19:00










  • If you read the manual it explains how to quit sed.
    – don_crissti
    May 16 at 19:02






  • 1




    Possible duplicate of sed command to find lines which are not of specific size
    – DopeGhoti
    May 16 at 19:31










  • @DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
    – don_crissti
    May 16 at 19:37










  • In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
    – DopeGhoti
    May 16 at 19:50















up vote
-3
down vote

favorite












how can I use sed to report any first record that is not of size 21 in a file?



I don't want sed to scan the complete file and get out as soon as the first record which is not of size 21 is found.







share|improve this question













closed as unclear what you're asking by DopeGhoti, steve, G-Man, dr01, X Tian May 17 at 15:59


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • i have the sed command i am not sure how to break out of it .
    – Ahmad S
    May 16 at 19:00










  • If you read the manual it explains how to quit sed.
    – don_crissti
    May 16 at 19:02






  • 1




    Possible duplicate of sed command to find lines which are not of specific size
    – DopeGhoti
    May 16 at 19:31










  • @DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
    – don_crissti
    May 16 at 19:37










  • In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
    – DopeGhoti
    May 16 at 19:50













up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











how can I use sed to report any first record that is not of size 21 in a file?



I don't want sed to scan the complete file and get out as soon as the first record which is not of size 21 is found.







share|improve this question













how can I use sed to report any first record that is not of size 21 in a file?



I don't want sed to scan the complete file and get out as soon as the first record which is not of size 21 is found.









share|improve this question












share|improve this question




share|improve this question








edited May 16 at 19:27









SivaPrasath

4,74212445




4,74212445









asked May 16 at 18:36









Ahmad S

11




11




closed as unclear what you're asking by DopeGhoti, steve, G-Man, dr01, X Tian May 17 at 15:59


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by DopeGhoti, steve, G-Man, dr01, X Tian May 17 at 15:59


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • i have the sed command i am not sure how to break out of it .
    – Ahmad S
    May 16 at 19:00










  • If you read the manual it explains how to quit sed.
    – don_crissti
    May 16 at 19:02






  • 1




    Possible duplicate of sed command to find lines which are not of specific size
    – DopeGhoti
    May 16 at 19:31










  • @DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
    – don_crissti
    May 16 at 19:37










  • In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
    – DopeGhoti
    May 16 at 19:50

















  • i have the sed command i am not sure how to break out of it .
    – Ahmad S
    May 16 at 19:00










  • If you read the manual it explains how to quit sed.
    – don_crissti
    May 16 at 19:02






  • 1




    Possible duplicate of sed command to find lines which are not of specific size
    – DopeGhoti
    May 16 at 19:31










  • @DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
    – don_crissti
    May 16 at 19:37










  • In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
    – DopeGhoti
    May 16 at 19:50
















i have the sed command i am not sure how to break out of it .
– Ahmad S
May 16 at 19:00




i have the sed command i am not sure how to break out of it .
– Ahmad S
May 16 at 19:00












If you read the manual it explains how to quit sed.
– don_crissti
May 16 at 19:02




If you read the manual it explains how to quit sed.
– don_crissti
May 16 at 19:02




1




1




Possible duplicate of sed command to find lines which are not of specific size
– DopeGhoti
May 16 at 19:31




Possible duplicate of sed command to find lines which are not of specific size
– DopeGhoti
May 16 at 19:31












@DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
– don_crissti
May 16 at 19:37




@DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
– don_crissti
May 16 at 19:37












In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
– DopeGhoti
May 16 at 19:50





In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
– DopeGhoti
May 16 at 19:50











3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










Based on this answer to your previous question



sed -n '/^.21$/! p;q;' file





share|improve this answer




























    up vote
    1
    down vote













    Using awk (this would be easiest):



    awk 'length != 21 printf("Line of length %d foundn", length); exit ' file


    Or, as part of a shell script,



    if ! awk 'length != 21 exit 1 ' file; then
    echo 'Line of length != 21 found (or awk failed to execute properly)'
    else
    echo 'All lines are 21 characters (or the file is empty)'
    fi



    Using sed:



    sed -nE '/^.21$/!p;q;' file


    With GNU sed, you would be able to do



    if ! sed -nE '/.21$/!q 1' file; then
    echo 'Line with != 21 characters found (or sed failed to run properly)'
    else
    echo 'All lines are 21 characters (or file is empty)'
    fi





    share|improve this answer























    • using sed please
      – Ahmad S
      May 16 at 19:00










    • @AhmadS See updated answer.
      – Kusalananda
      May 16 at 19:12

















    up vote
    1
    down vote













    With GNU grep:



    if line=$(grep -Exnvm1 '.21' < file); then
    printf >&2 'Found "%s" which is not 21 characters longn' "$line"
    fi


    (-n above includes the line number)






    share|improve this answer




























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted










      Based on this answer to your previous question



      sed -n '/^.21$/! p;q;' file





      share|improve this answer

























        up vote
        1
        down vote



        accepted










        Based on this answer to your previous question



        sed -n '/^.21$/! p;q;' file





        share|improve this answer























          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Based on this answer to your previous question



          sed -n '/^.21$/! p;q;' file





          share|improve this answer













          Based on this answer to your previous question



          sed -n '/^.21$/! p;q;' file






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered May 16 at 19:08









          steeldriver

          31.2k34978




          31.2k34978






















              up vote
              1
              down vote













              Using awk (this would be easiest):



              awk 'length != 21 printf("Line of length %d foundn", length); exit ' file


              Or, as part of a shell script,



              if ! awk 'length != 21 exit 1 ' file; then
              echo 'Line of length != 21 found (or awk failed to execute properly)'
              else
              echo 'All lines are 21 characters (or the file is empty)'
              fi



              Using sed:



              sed -nE '/^.21$/!p;q;' file


              With GNU sed, you would be able to do



              if ! sed -nE '/.21$/!q 1' file; then
              echo 'Line with != 21 characters found (or sed failed to run properly)'
              else
              echo 'All lines are 21 characters (or file is empty)'
              fi





              share|improve this answer























              • using sed please
                – Ahmad S
                May 16 at 19:00










              • @AhmadS See updated answer.
                – Kusalananda
                May 16 at 19:12














              up vote
              1
              down vote













              Using awk (this would be easiest):



              awk 'length != 21 printf("Line of length %d foundn", length); exit ' file


              Or, as part of a shell script,



              if ! awk 'length != 21 exit 1 ' file; then
              echo 'Line of length != 21 found (or awk failed to execute properly)'
              else
              echo 'All lines are 21 characters (or the file is empty)'
              fi



              Using sed:



              sed -nE '/^.21$/!p;q;' file


              With GNU sed, you would be able to do



              if ! sed -nE '/.21$/!q 1' file; then
              echo 'Line with != 21 characters found (or sed failed to run properly)'
              else
              echo 'All lines are 21 characters (or file is empty)'
              fi





              share|improve this answer























              • using sed please
                – Ahmad S
                May 16 at 19:00










              • @AhmadS See updated answer.
                – Kusalananda
                May 16 at 19:12












              up vote
              1
              down vote










              up vote
              1
              down vote









              Using awk (this would be easiest):



              awk 'length != 21 printf("Line of length %d foundn", length); exit ' file


              Or, as part of a shell script,



              if ! awk 'length != 21 exit 1 ' file; then
              echo 'Line of length != 21 found (or awk failed to execute properly)'
              else
              echo 'All lines are 21 characters (or the file is empty)'
              fi



              Using sed:



              sed -nE '/^.21$/!p;q;' file


              With GNU sed, you would be able to do



              if ! sed -nE '/.21$/!q 1' file; then
              echo 'Line with != 21 characters found (or sed failed to run properly)'
              else
              echo 'All lines are 21 characters (or file is empty)'
              fi





              share|improve this answer















              Using awk (this would be easiest):



              awk 'length != 21 printf("Line of length %d foundn", length); exit ' file


              Or, as part of a shell script,



              if ! awk 'length != 21 exit 1 ' file; then
              echo 'Line of length != 21 found (or awk failed to execute properly)'
              else
              echo 'All lines are 21 characters (or the file is empty)'
              fi



              Using sed:



              sed -nE '/^.21$/!p;q;' file


              With GNU sed, you would be able to do



              if ! sed -nE '/.21$/!q 1' file; then
              echo 'Line with != 21 characters found (or sed failed to run properly)'
              else
              echo 'All lines are 21 characters (or file is empty)'
              fi






              share|improve this answer















              share|improve this answer



              share|improve this answer








              edited May 16 at 19:12


























              answered May 16 at 18:42









              Kusalananda

              102k13199315




              102k13199315











              • using sed please
                – Ahmad S
                May 16 at 19:00










              • @AhmadS See updated answer.
                – Kusalananda
                May 16 at 19:12
















              • using sed please
                – Ahmad S
                May 16 at 19:00










              • @AhmadS See updated answer.
                – Kusalananda
                May 16 at 19:12















              using sed please
              – Ahmad S
              May 16 at 19:00




              using sed please
              – Ahmad S
              May 16 at 19:00












              @AhmadS See updated answer.
              – Kusalananda
              May 16 at 19:12




              @AhmadS See updated answer.
              – Kusalananda
              May 16 at 19:12










              up vote
              1
              down vote













              With GNU grep:



              if line=$(grep -Exnvm1 '.21' < file); then
              printf >&2 'Found "%s" which is not 21 characters longn' "$line"
              fi


              (-n above includes the line number)






              share|improve this answer

























                up vote
                1
                down vote













                With GNU grep:



                if line=$(grep -Exnvm1 '.21' < file); then
                printf >&2 'Found "%s" which is not 21 characters longn' "$line"
                fi


                (-n above includes the line number)






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  With GNU grep:



                  if line=$(grep -Exnvm1 '.21' < file); then
                  printf >&2 'Found "%s" which is not 21 characters longn' "$line"
                  fi


                  (-n above includes the line number)






                  share|improve this answer













                  With GNU grep:



                  if line=$(grep -Exnvm1 '.21' < file); then
                  printf >&2 'Found "%s" which is not 21 characters longn' "$line"
                  fi


                  (-n above includes the line number)







                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered May 16 at 21:36









                  Stéphane Chazelas

                  279k53513845




                  279k53513845












                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay