I have a file, which has one line which is less than 20 characters length.

I wanted to find the line number and remove that line alone from that file.


Using grep:

grep -vn '.\{20,\}' infile

sed approach:

sed -i '/^.\{1,19\}$/d' file

Using awk:

awk 'length >= 20' file

or, for the complete "remove those lines from the file" scenario:

awk 'length >= 20' file >tmpfile && mv tmpfile file

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.