[Perl-beginners] Delete first line when blank
Mar 7, 2014 at 9:58 pm
I have some text files from which I would like to remove the first
line, but only if it's blank. Any hints? I tried a few things, but
the results haven't quite been satisfactory.
: You should be able to do that in just a few lines of Perl: 1. Open the existing file for reading. 2. Open a new file for writing. 3. Read the first line in the input file. 4. If the first line is not blank, write it to the output file. 5. Read the remaining lines from the input file and write to the output file. 6. Close both files 7. Optionally: rename both files to give the new file the same name as the old file. If you don't understand any of the steps, just ask. If you have trouble, post
: perl -pi -e '$_ = "" if ( $. == 1 && /^\n/);' filename on command line would be my first shot. Greetings, Janek
Add Line break when first of a line changes
finding Makefiles which containing a backslash continuation character where the next line is blank or whitespace
Illegal character error for blank line.
Delete multiple blank lines
DELETE BLANK LINE
regexp for a blank line
How to process blank line delimeted blocks of text?
Substituting a text
1 of 3
Mar 7, '14 at 9:58p
Mar 8, '14 at 7:37a
3 users in discussion
Janek Schleicher (1)
Jim Gibson (1)
Groups & Organizations
site design / logo © 2022 Grokbase