I have a list of items in a file,
foobar
barfoo
bar
faaboo
foo
boofar
fo
b
Using perl, I’m just after script that will go through the filename and delete all items 3 characters or less. Overwrite the existing filename (without creating a new, or temp filename), Thus the list will be become.
foobar
barfoo
faaboo
boofar
One-liner:
You can use
length(add 1 for newline character) instead of regex if that’s your fancy, as Jonathan Leffler noted in comments – it’s probably faster on very large files. Here’s a Windows version (note the use of double quotes required bycmdinstead of single quotes):Also, to answer your comment, unfortunately you can not execute in-place
-iedits on Windows without a backup file. Please refer to this SO post for detailed explanation (again, Windows limitation, not Perl’s) as well as a workaround.