in reply to Re^2: Way to remove the new line characters at the end of the content in a file
in thread Way to remove the new line characters at the end of the content in a file
Lines containing e.g. a lone } will be removed with that.Oops, that's right, but I based the one-liner on the sample data shown by the OP, i.e. a file with a list of server names, which ought to contain some alphanumerical characters (and/or empty lines), not Perl or C code.
Perhaps a stricter version:
But even this might also fail on some edge cases, the really right regex really depends on the actual content of the file being processed.perl -ni.bak -e "print $_ unless /^[\n\s]+$/;" my_file.txt
|
|---|