How to delete line if longer than XY? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsRemove line of exactly n charactersOnly keep lines containing x or less number of numbers. TXT fileHow to delete lines where the given part of the line is more than 100 chars?Delete First line of a fileHow to remove lines shorter than XY?Delete whole line if after “:” less than 4 charsDelete every Nth line in shellHow to remove line based on Delimeter in perl / Shell?How to remove line break if line character count less than n charsHow to delete certain line from file?Conditionally delete a line from filefind lines longer than X in JSON and delete the whole object

Typeface like Times New Roman but with "tied" percent sign

Is there a writing software that you can sort scenes like slides in PowerPoint?

Netflix Recommendations?

What can I do if neighbor is blocking my solar panels intentionally?

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

Semisimplicity of the category of coherent sheaves?

How can I protect witches in combat who wear limited clothing?

Why is superheterodyning better than direct conversion?

Was credit for the black hole image misattributed?

Simulation of a banking system with an Account class in C++

Why can't wing-mounted spoilers be used to steepen approaches?

Simulating Exploding Dice

Can withdrawing asylum be illegal?

Did God make two great lights or did He make the great light two?

Does Parliament need to approve the new Brexit delay to 31 October 2019?

The variadic template constructor of my class cannot modify my class members, why is that so?

Didn't get enough time to take a Coding Test - what to do now?

Would an alien lifeform be able to achieve space travel if lacking in vision?

Segmentation fault output is suppressed when piping stdin into a function. Why?

Python - Fishing Simulator

Relations between two reciprocal partial derivatives?

Did the new image of black hole confirm the general theory of relativity?

How many people can fit inside Mordenkainen's Magnificent Mansion?



How to delete line if longer than XY?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election ResultsRemove line of exactly n charactersOnly keep lines containing x or less number of numbers. TXT fileHow to delete lines where the given part of the line is more than 100 chars?Delete First line of a fileHow to remove lines shorter than XY?Delete whole line if after “:” less than 4 charsDelete every Nth line in shellHow to remove line based on Delimeter in perl / Shell?How to remove line break if line character count less than n charsHow to delete certain line from file?Conditionally delete a line from filefind lines longer than X in JSON and delete the whole object



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








19















How can i delete a line if it is longer than e.g.: 2048 chars?










share|improve this question
























  • Do you insist on using sed? This is easy, for example in python. And no doubt even easier in perl. Though the question is not terribly well defined. Copy a file, removing all lines longer than 2048, or something else?

    – Faheem Mitha
    Mar 23 '11 at 18:21


















19















How can i delete a line if it is longer than e.g.: 2048 chars?










share|improve this question
























  • Do you insist on using sed? This is easy, for example in python. And no doubt even easier in perl. Though the question is not terribly well defined. Copy a file, removing all lines longer than 2048, or something else?

    – Faheem Mitha
    Mar 23 '11 at 18:21














19












19








19


2






How can i delete a line if it is longer than e.g.: 2048 chars?










share|improve this question
















How can i delete a line if it is longer than e.g.: 2048 chars?







sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 29 '14 at 17:27









jlliagre

47.9k786138




47.9k786138










asked Mar 23 '11 at 18:09









LanceBaynesLanceBaynes

10.9k77202328




10.9k77202328












  • Do you insist on using sed? This is easy, for example in python. And no doubt even easier in perl. Though the question is not terribly well defined. Copy a file, removing all lines longer than 2048, or something else?

    – Faheem Mitha
    Mar 23 '11 at 18:21


















  • Do you insist on using sed? This is easy, for example in python. And no doubt even easier in perl. Though the question is not terribly well defined. Copy a file, removing all lines longer than 2048, or something else?

    – Faheem Mitha
    Mar 23 '11 at 18:21

















Do you insist on using sed? This is easy, for example in python. And no doubt even easier in perl. Though the question is not terribly well defined. Copy a file, removing all lines longer than 2048, or something else?

– Faheem Mitha
Mar 23 '11 at 18:21






Do you insist on using sed? This is easy, for example in python. And no doubt even easier in perl. Though the question is not terribly well defined. Copy a file, removing all lines longer than 2048, or something else?

– Faheem Mitha
Mar 23 '11 at 18:21











6 Answers
6






active

oldest

votes


















21














sed '/^.2048./d' input.txt > output.txt





share|improve this answer




















  • 3





    I get the error message sed: 1: "/^.2048..*/d": RE error: invalid repetition count(s) (Mac OS X)

    – wedi
    Oct 13 '14 at 15:47






  • 1





    @wedi you probably want to install the GNU version instead of the BSD version that ships with Mac. This is easy with brew

    – Freedom_Ben
    Jul 6 '16 at 0:00



















7














Here's a solution which deletes lines that has 2049 or more characters:



sed -E '/.2049/d' <file.in >file.out


The expression /.2049/d will match any line that contains at least 2049 characters and deletes them from the input, producing only shorter line on the output.



With awk, printing lines of length 2048 or shorter:



awk 'length <= 2048' <file.in >file.out


Mimicking the sed solution literally with awk:



awk 'length >= 2049 next print ' <file.in >file.out





share|improve this answer




















  • 1





    I get the error message sed: 1: "/^.400,$/d": RE error: invalid repetition count(s) (Mac OS X)

    – wedi
    Oct 13 '14 at 15:47







  • 1





    @wedi Now updated and tested on macOS Mojave.

    – Kusalananda
    Nov 29 '18 at 23:20


















2














Something like this should work in Python.



of = open("orig")
nf = open("new",'w')
for line in of:
if len(line) < 2048:
nf.write(line)
of.close()
nf.close()





share|improve this answer


















  • 1





    Personally, @Faheem, I prefer your answer. The reason why is that it was very easy for me to turn it around into 'delete all lines smaller than x'. I don't use Python all the time, but when I do I always feel I should learn it well.

    – ixtmixilix
    May 22 '11 at 18:18











  • @ixtmixilix: Yes, using a full featured language like Python is pretty flexible. Thanks for the comment.

    – Faheem Mitha
    May 24 '11 at 16:46


















1














perl -lne "length < 2048 && print" infile > outfile





share|improve this answer























  • +1 The -l isn't needed, though.

    – Joseph R.
    Jan 29 '14 at 17:22












  • Does not work for me. Perl v5.16.2. Warning: Use of "length" without parentheses is ambiguous at -e line 1. Unterminated <> operator at -e line 1.

    – wedi
    Oct 13 '14 at 15:51











  • You may try length($_) > 2048 && print. length is a shortcut for length($_) anyway.

    – MaratC
    Nov 17 '14 at 12:10


















0














The above answers do not work for me on Mac OS X 10.9.5.



The following code does work:



sed '/.2048/d'.



Although not asked, but provided for reference, the reverse can be achieved the following code:



sed '/.2048/!d'.






share|improve this answer

























  • lol, but sed: 1: "/.2048/d": RE error: invalid repetition count(s) (Mac OS X, 10.10.4)

    – alex gray
    Jul 24 '15 at 13:29











  • Ah. I installed the GNU version instead of the BSD version that ships with Mac as @Freedom_Ben suggested above. But Kusalananda found the switch to enable extended regex. So you should go with his solution if you still have that problem. ;)

    – wedi
    Nov 30 '18 at 19:40


















0














With gnu-sed, you may use the -r flag, to avoid typing the backslashes, and a comma, to define an open interval:



sed -r "/.2049,/d" input.txt > output.txt


with:



  • x2049 meaning exactly 2049 xs

  • x2049,3072 meaning from 2049 to 3072 xs

  • x2049, meaning at least 2049 xs

  • x,2049 meaning at most 2049 xs

For the intervals, to not match bigger patterns, you would need line anchors like



sed -r "/^.32,64$/d" input.txt > output.txt 





share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f9981%2fhow-to-delete-line-if-longer-than-xy%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    6 Answers
    6






    active

    oldest

    votes








    6 Answers
    6






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    21














    sed '/^.2048./d' input.txt > output.txt





    share|improve this answer




















    • 3





      I get the error message sed: 1: "/^.2048..*/d": RE error: invalid repetition count(s) (Mac OS X)

      – wedi
      Oct 13 '14 at 15:47






    • 1





      @wedi you probably want to install the GNU version instead of the BSD version that ships with Mac. This is easy with brew

      – Freedom_Ben
      Jul 6 '16 at 0:00
















    21














    sed '/^.2048./d' input.txt > output.txt





    share|improve this answer




















    • 3





      I get the error message sed: 1: "/^.2048..*/d": RE error: invalid repetition count(s) (Mac OS X)

      – wedi
      Oct 13 '14 at 15:47






    • 1





      @wedi you probably want to install the GNU version instead of the BSD version that ships with Mac. This is easy with brew

      – Freedom_Ben
      Jul 6 '16 at 0:00














    21












    21








    21







    sed '/^.2048./d' input.txt > output.txt





    share|improve this answer















    sed '/^.2048./d' input.txt > output.txt






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 1 '16 at 0:43









    Wildcard

    23.3k1067171




    23.3k1067171










    answered Mar 23 '11 at 18:26









    forcefsckforcefsck

    5,8362231




    5,8362231







    • 3





      I get the error message sed: 1: "/^.2048..*/d": RE error: invalid repetition count(s) (Mac OS X)

      – wedi
      Oct 13 '14 at 15:47






    • 1





      @wedi you probably want to install the GNU version instead of the BSD version that ships with Mac. This is easy with brew

      – Freedom_Ben
      Jul 6 '16 at 0:00













    • 3





      I get the error message sed: 1: "/^.2048..*/d": RE error: invalid repetition count(s) (Mac OS X)

      – wedi
      Oct 13 '14 at 15:47






    • 1





      @wedi you probably want to install the GNU version instead of the BSD version that ships with Mac. This is easy with brew

      – Freedom_Ben
      Jul 6 '16 at 0:00








    3




    3





    I get the error message sed: 1: "/^.2048..*/d": RE error: invalid repetition count(s) (Mac OS X)

    – wedi
    Oct 13 '14 at 15:47





    I get the error message sed: 1: "/^.2048..*/d": RE error: invalid repetition count(s) (Mac OS X)

    – wedi
    Oct 13 '14 at 15:47




    1




    1





    @wedi you probably want to install the GNU version instead of the BSD version that ships with Mac. This is easy with brew

    – Freedom_Ben
    Jul 6 '16 at 0:00






    @wedi you probably want to install the GNU version instead of the BSD version that ships with Mac. This is easy with brew

    – Freedom_Ben
    Jul 6 '16 at 0:00














    7














    Here's a solution which deletes lines that has 2049 or more characters:



    sed -E '/.2049/d' <file.in >file.out


    The expression /.2049/d will match any line that contains at least 2049 characters and deletes them from the input, producing only shorter line on the output.



    With awk, printing lines of length 2048 or shorter:



    awk 'length <= 2048' <file.in >file.out


    Mimicking the sed solution literally with awk:



    awk 'length >= 2049 next print ' <file.in >file.out





    share|improve this answer




















    • 1





      I get the error message sed: 1: "/^.400,$/d": RE error: invalid repetition count(s) (Mac OS X)

      – wedi
      Oct 13 '14 at 15:47







    • 1





      @wedi Now updated and tested on macOS Mojave.

      – Kusalananda
      Nov 29 '18 at 23:20















    7














    Here's a solution which deletes lines that has 2049 or more characters:



    sed -E '/.2049/d' <file.in >file.out


    The expression /.2049/d will match any line that contains at least 2049 characters and deletes them from the input, producing only shorter line on the output.



    With awk, printing lines of length 2048 or shorter:



    awk 'length <= 2048' <file.in >file.out


    Mimicking the sed solution literally with awk:



    awk 'length >= 2049 next print ' <file.in >file.out





    share|improve this answer




















    • 1





      I get the error message sed: 1: "/^.400,$/d": RE error: invalid repetition count(s) (Mac OS X)

      – wedi
      Oct 13 '14 at 15:47







    • 1





      @wedi Now updated and tested on macOS Mojave.

      – Kusalananda
      Nov 29 '18 at 23:20













    7












    7








    7







    Here's a solution which deletes lines that has 2049 or more characters:



    sed -E '/.2049/d' <file.in >file.out


    The expression /.2049/d will match any line that contains at least 2049 characters and deletes them from the input, producing only shorter line on the output.



    With awk, printing lines of length 2048 or shorter:



    awk 'length <= 2048' <file.in >file.out


    Mimicking the sed solution literally with awk:



    awk 'length >= 2049 next print ' <file.in >file.out





    share|improve this answer















    Here's a solution which deletes lines that has 2049 or more characters:



    sed -E '/.2049/d' <file.in >file.out


    The expression /.2049/d will match any line that contains at least 2049 characters and deletes them from the input, producing only shorter line on the output.



    With awk, printing lines of length 2048 or shorter:



    awk 'length <= 2048' <file.in >file.out


    Mimicking the sed solution literally with awk:



    awk 'length >= 2049 next print ' <file.in >file.out






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited yesterday

























    answered Sep 7 '11 at 10:13









    KusalanandaKusalananda

    141k18263439




    141k18263439







    • 1





      I get the error message sed: 1: "/^.400,$/d": RE error: invalid repetition count(s) (Mac OS X)

      – wedi
      Oct 13 '14 at 15:47







    • 1





      @wedi Now updated and tested on macOS Mojave.

      – Kusalananda
      Nov 29 '18 at 23:20












    • 1





      I get the error message sed: 1: "/^.400,$/d": RE error: invalid repetition count(s) (Mac OS X)

      – wedi
      Oct 13 '14 at 15:47







    • 1





      @wedi Now updated and tested on macOS Mojave.

      – Kusalananda
      Nov 29 '18 at 23:20







    1




    1





    I get the error message sed: 1: "/^.400,$/d": RE error: invalid repetition count(s) (Mac OS X)

    – wedi
    Oct 13 '14 at 15:47






    I get the error message sed: 1: "/^.400,$/d": RE error: invalid repetition count(s) (Mac OS X)

    – wedi
    Oct 13 '14 at 15:47





    1




    1





    @wedi Now updated and tested on macOS Mojave.

    – Kusalananda
    Nov 29 '18 at 23:20





    @wedi Now updated and tested on macOS Mojave.

    – Kusalananda
    Nov 29 '18 at 23:20











    2














    Something like this should work in Python.



    of = open("orig")
    nf = open("new",'w')
    for line in of:
    if len(line) < 2048:
    nf.write(line)
    of.close()
    nf.close()





    share|improve this answer


















    • 1





      Personally, @Faheem, I prefer your answer. The reason why is that it was very easy for me to turn it around into 'delete all lines smaller than x'. I don't use Python all the time, but when I do I always feel I should learn it well.

      – ixtmixilix
      May 22 '11 at 18:18











    • @ixtmixilix: Yes, using a full featured language like Python is pretty flexible. Thanks for the comment.

      – Faheem Mitha
      May 24 '11 at 16:46















    2














    Something like this should work in Python.



    of = open("orig")
    nf = open("new",'w')
    for line in of:
    if len(line) < 2048:
    nf.write(line)
    of.close()
    nf.close()





    share|improve this answer


















    • 1





      Personally, @Faheem, I prefer your answer. The reason why is that it was very easy for me to turn it around into 'delete all lines smaller than x'. I don't use Python all the time, but when I do I always feel I should learn it well.

      – ixtmixilix
      May 22 '11 at 18:18











    • @ixtmixilix: Yes, using a full featured language like Python is pretty flexible. Thanks for the comment.

      – Faheem Mitha
      May 24 '11 at 16:46













    2












    2








    2







    Something like this should work in Python.



    of = open("orig")
    nf = open("new",'w')
    for line in of:
    if len(line) < 2048:
    nf.write(line)
    of.close()
    nf.close()





    share|improve this answer













    Something like this should work in Python.



    of = open("orig")
    nf = open("new",'w')
    for line in of:
    if len(line) < 2048:
    nf.write(line)
    of.close()
    nf.close()






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 23 '11 at 18:33









    Faheem MithaFaheem Mitha

    23.4k1885137




    23.4k1885137







    • 1





      Personally, @Faheem, I prefer your answer. The reason why is that it was very easy for me to turn it around into 'delete all lines smaller than x'. I don't use Python all the time, but when I do I always feel I should learn it well.

      – ixtmixilix
      May 22 '11 at 18:18











    • @ixtmixilix: Yes, using a full featured language like Python is pretty flexible. Thanks for the comment.

      – Faheem Mitha
      May 24 '11 at 16:46












    • 1





      Personally, @Faheem, I prefer your answer. The reason why is that it was very easy for me to turn it around into 'delete all lines smaller than x'. I don't use Python all the time, but when I do I always feel I should learn it well.

      – ixtmixilix
      May 22 '11 at 18:18











    • @ixtmixilix: Yes, using a full featured language like Python is pretty flexible. Thanks for the comment.

      – Faheem Mitha
      May 24 '11 at 16:46







    1




    1





    Personally, @Faheem, I prefer your answer. The reason why is that it was very easy for me to turn it around into 'delete all lines smaller than x'. I don't use Python all the time, but when I do I always feel I should learn it well.

    – ixtmixilix
    May 22 '11 at 18:18





    Personally, @Faheem, I prefer your answer. The reason why is that it was very easy for me to turn it around into 'delete all lines smaller than x'. I don't use Python all the time, but when I do I always feel I should learn it well.

    – ixtmixilix
    May 22 '11 at 18:18













    @ixtmixilix: Yes, using a full featured language like Python is pretty flexible. Thanks for the comment.

    – Faheem Mitha
    May 24 '11 at 16:46





    @ixtmixilix: Yes, using a full featured language like Python is pretty flexible. Thanks for the comment.

    – Faheem Mitha
    May 24 '11 at 16:46











    1














    perl -lne "length < 2048 && print" infile > outfile





    share|improve this answer























    • +1 The -l isn't needed, though.

      – Joseph R.
      Jan 29 '14 at 17:22












    • Does not work for me. Perl v5.16.2. Warning: Use of "length" without parentheses is ambiguous at -e line 1. Unterminated <> operator at -e line 1.

      – wedi
      Oct 13 '14 at 15:51











    • You may try length($_) > 2048 && print. length is a shortcut for length($_) anyway.

      – MaratC
      Nov 17 '14 at 12:10















    1














    perl -lne "length < 2048 && print" infile > outfile





    share|improve this answer























    • +1 The -l isn't needed, though.

      – Joseph R.
      Jan 29 '14 at 17:22












    • Does not work for me. Perl v5.16.2. Warning: Use of "length" without parentheses is ambiguous at -e line 1. Unterminated <> operator at -e line 1.

      – wedi
      Oct 13 '14 at 15:51











    • You may try length($_) > 2048 && print. length is a shortcut for length($_) anyway.

      – MaratC
      Nov 17 '14 at 12:10













    1












    1








    1







    perl -lne "length < 2048 && print" infile > outfile





    share|improve this answer













    perl -lne "length < 2048 && print" infile > outfile






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 29 '14 at 17:14









    MaratCMaratC

    1111




    1111












    • +1 The -l isn't needed, though.

      – Joseph R.
      Jan 29 '14 at 17:22












    • Does not work for me. Perl v5.16.2. Warning: Use of "length" without parentheses is ambiguous at -e line 1. Unterminated <> operator at -e line 1.

      – wedi
      Oct 13 '14 at 15:51











    • You may try length($_) > 2048 && print. length is a shortcut for length($_) anyway.

      – MaratC
      Nov 17 '14 at 12:10

















    • +1 The -l isn't needed, though.

      – Joseph R.
      Jan 29 '14 at 17:22












    • Does not work for me. Perl v5.16.2. Warning: Use of "length" without parentheses is ambiguous at -e line 1. Unterminated <> operator at -e line 1.

      – wedi
      Oct 13 '14 at 15:51











    • You may try length($_) > 2048 && print. length is a shortcut for length($_) anyway.

      – MaratC
      Nov 17 '14 at 12:10
















    +1 The -l isn't needed, though.

    – Joseph R.
    Jan 29 '14 at 17:22






    +1 The -l isn't needed, though.

    – Joseph R.
    Jan 29 '14 at 17:22














    Does not work for me. Perl v5.16.2. Warning: Use of "length" without parentheses is ambiguous at -e line 1. Unterminated <> operator at -e line 1.

    – wedi
    Oct 13 '14 at 15:51





    Does not work for me. Perl v5.16.2. Warning: Use of "length" without parentheses is ambiguous at -e line 1. Unterminated <> operator at -e line 1.

    – wedi
    Oct 13 '14 at 15:51













    You may try length($_) > 2048 && print. length is a shortcut for length($_) anyway.

    – MaratC
    Nov 17 '14 at 12:10





    You may try length($_) > 2048 && print. length is a shortcut for length($_) anyway.

    – MaratC
    Nov 17 '14 at 12:10











    0














    The above answers do not work for me on Mac OS X 10.9.5.



    The following code does work:



    sed '/.2048/d'.



    Although not asked, but provided for reference, the reverse can be achieved the following code:



    sed '/.2048/!d'.






    share|improve this answer

























    • lol, but sed: 1: "/.2048/d": RE error: invalid repetition count(s) (Mac OS X, 10.10.4)

      – alex gray
      Jul 24 '15 at 13:29











    • Ah. I installed the GNU version instead of the BSD version that ships with Mac as @Freedom_Ben suggested above. But Kusalananda found the switch to enable extended regex. So you should go with his solution if you still have that problem. ;)

      – wedi
      Nov 30 '18 at 19:40















    0














    The above answers do not work for me on Mac OS X 10.9.5.



    The following code does work:



    sed '/.2048/d'.



    Although not asked, but provided for reference, the reverse can be achieved the following code:



    sed '/.2048/!d'.






    share|improve this answer

























    • lol, but sed: 1: "/.2048/d": RE error: invalid repetition count(s) (Mac OS X, 10.10.4)

      – alex gray
      Jul 24 '15 at 13:29











    • Ah. I installed the GNU version instead of the BSD version that ships with Mac as @Freedom_Ben suggested above. But Kusalananda found the switch to enable extended regex. So you should go with his solution if you still have that problem. ;)

      – wedi
      Nov 30 '18 at 19:40













    0












    0








    0







    The above answers do not work for me on Mac OS X 10.9.5.



    The following code does work:



    sed '/.2048/d'.



    Although not asked, but provided for reference, the reverse can be achieved the following code:



    sed '/.2048/!d'.






    share|improve this answer















    The above answers do not work for me on Mac OS X 10.9.5.



    The following code does work:



    sed '/.2048/d'.



    Although not asked, but provided for reference, the reverse can be achieved the following code:



    sed '/.2048/!d'.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 15 '16 at 21:28









    DomainsFeatured

    1348




    1348










    answered Oct 13 '14 at 16:02









    wediwedi

    1686




    1686












    • lol, but sed: 1: "/.2048/d": RE error: invalid repetition count(s) (Mac OS X, 10.10.4)

      – alex gray
      Jul 24 '15 at 13:29











    • Ah. I installed the GNU version instead of the BSD version that ships with Mac as @Freedom_Ben suggested above. But Kusalananda found the switch to enable extended regex. So you should go with his solution if you still have that problem. ;)

      – wedi
      Nov 30 '18 at 19:40

















    • lol, but sed: 1: "/.2048/d": RE error: invalid repetition count(s) (Mac OS X, 10.10.4)

      – alex gray
      Jul 24 '15 at 13:29











    • Ah. I installed the GNU version instead of the BSD version that ships with Mac as @Freedom_Ben suggested above. But Kusalananda found the switch to enable extended regex. So you should go with his solution if you still have that problem. ;)

      – wedi
      Nov 30 '18 at 19:40
















    lol, but sed: 1: "/.2048/d": RE error: invalid repetition count(s) (Mac OS X, 10.10.4)

    – alex gray
    Jul 24 '15 at 13:29





    lol, but sed: 1: "/.2048/d": RE error: invalid repetition count(s) (Mac OS X, 10.10.4)

    – alex gray
    Jul 24 '15 at 13:29













    Ah. I installed the GNU version instead of the BSD version that ships with Mac as @Freedom_Ben suggested above. But Kusalananda found the switch to enable extended regex. So you should go with his solution if you still have that problem. ;)

    – wedi
    Nov 30 '18 at 19:40





    Ah. I installed the GNU version instead of the BSD version that ships with Mac as @Freedom_Ben suggested above. But Kusalananda found the switch to enable extended regex. So you should go with his solution if you still have that problem. ;)

    – wedi
    Nov 30 '18 at 19:40











    0














    With gnu-sed, you may use the -r flag, to avoid typing the backslashes, and a comma, to define an open interval:



    sed -r "/.2049,/d" input.txt > output.txt


    with:



    • x2049 meaning exactly 2049 xs

    • x2049,3072 meaning from 2049 to 3072 xs

    • x2049, meaning at least 2049 xs

    • x,2049 meaning at most 2049 xs

    For the intervals, to not match bigger patterns, you would need line anchors like



    sed -r "/^.32,64$/d" input.txt > output.txt 





    share|improve this answer



























      0














      With gnu-sed, you may use the -r flag, to avoid typing the backslashes, and a comma, to define an open interval:



      sed -r "/.2049,/d" input.txt > output.txt


      with:



      • x2049 meaning exactly 2049 xs

      • x2049,3072 meaning from 2049 to 3072 xs

      • x2049, meaning at least 2049 xs

      • x,2049 meaning at most 2049 xs

      For the intervals, to not match bigger patterns, you would need line anchors like



      sed -r "/^.32,64$/d" input.txt > output.txt 





      share|improve this answer

























        0












        0








        0







        With gnu-sed, you may use the -r flag, to avoid typing the backslashes, and a comma, to define an open interval:



        sed -r "/.2049,/d" input.txt > output.txt


        with:



        • x2049 meaning exactly 2049 xs

        • x2049,3072 meaning from 2049 to 3072 xs

        • x2049, meaning at least 2049 xs

        • x,2049 meaning at most 2049 xs

        For the intervals, to not match bigger patterns, you would need line anchors like



        sed -r "/^.32,64$/d" input.txt > output.txt 





        share|improve this answer













        With gnu-sed, you may use the -r flag, to avoid typing the backslashes, and a comma, to define an open interval:



        sed -r "/.2049,/d" input.txt > output.txt


        with:



        • x2049 meaning exactly 2049 xs

        • x2049,3072 meaning from 2049 to 3072 xs

        • x2049, meaning at least 2049 xs

        • x,2049 meaning at most 2049 xs

        For the intervals, to not match bigger patterns, you would need line anchors like



        sed -r "/^.32,64$/d" input.txt > output.txt 






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 30 '18 at 0:17









        user unknownuser unknown

        7,46112450




        7,46112450



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f9981%2fhow-to-delete-line-if-longer-than-xy%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            -sed

            Popular posts from this blog

            Mobil Contents History Mobil brands Former Mobil brands Lukoil transaction Mobil UK Mobil Australia Mobil New Zealand Mobil Greece Mobil in Japan Mobil in Canada Mobil Egypt See also References External links Navigation menuwww.mobil.com"Mobil Corporation"the original"Our Houston campus""Business & Finance: Socony-Vacuum Corp.""Popular Mechanics""Lubrite Technologies""Exxon Mobil campus 'clearly happening'""Toledo Blade - Google News Archive Search""The Lion and the Moose - How 2 Executives Pulled off the Biggest Merger Ever""ExxonMobil Press Release""Lubricants""Archived copy"the original"Mobil 1™ and Mobil Super™ motor oil and synthetic motor oil - Mobil™ Motor Oils""Mobil Delvac""Mobil Industrial website""The State of Competition in Gasoline Marketing: The Effects of Refiner Operations at Retail""Mobil Travel Guide to become Forbes Travel Guide""Hotel Rankings: Forbes Merges with Mobil"the original"Jamieson oil industry history""Mobil news""Caltex pumps for control""Watchdog blocks Caltex bid""Exxon Mobil sells service station network""Mobil Oil New Zealand Limited is New Zealand's oldest oil company, with predecessor companies having first established a presence in the country in 1896""ExxonMobil subsidiaries have a business history in New Zealand stretching back more than 120 years. We are involved in petroleum refining and distribution and the marketing of fuels, lubricants and chemical products""Archived copy"the original"Exxon Mobil to Sell Its Japanese Arm for $3.9 Billion""Gas station merger will end Esso and Mobil's long run in Japan""Esso moves to affiliate itself with PC Optimum, no longer Aeroplan, in loyalty point switch""Mobil brand of gas stations to launch in Canada after deal for 213 Loblaws-owned locations""Mobil Nears Completion of Rebranding 200 Loblaw Gas Stations""Learn about ExxonMobil's operations in Egypt""Petrol and Diesel Service Stations in Egypt - Mobil"Official websiteExxon Mobil corporate websiteMobil Industrial official websiteeeeeeeeDA04275022275790-40000 0001 0860 5061n82045453134887257134887257

            Frič See also Navigation menuinternal link

            Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant