Jacko
Jacko

Reputation: 13195

need perl one liner to remove blank lines from beginning of file

I have the following script to strip a license region from a file, but I am left with a blank line at the beginning.

perl -pi~ -ne 'if (/#region License/../#endregion/) {$_ = "" if ($. == 1 || $. == 2)}' $i

Upvotes: 2

Views: 592

Answers (1)

ikegami
ikegami

Reputation: 385789

perl -i~ -ne'
    next if /#region License/../#endregion/;
    next if !$body && /^\s+\z/;
    ++$body;
    print;
' "$i"

Feel free to remove the line breaks, although it will work with them. They're there for readability.

Upvotes: 4

Related Questions