How can i delete a line, if it's longer then e.g.: 2048 chars?

link|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
feedback

3 Answers

up vote 9 down vote accepted
sed '/^.\{2048\}..*/d' input.txt > output.txt
link|improve this answer
feedback

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()
link|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
feedback

Here's a solution which doesn't use extended regular expressions:

sed '/^.\{2048,\}$/d' file.in >file.out
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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