Skip to main content
Notice removed Reward existing answer by Gordon
Bounty Ended with Stack EG's answer chosen by Gordon
added 32 characters in body; edited tags; edited title
Source Link
ilkkachu
  • 147.8k
  • 16
  • 268
  • 441

How to remove empty lines from beginbeginning and end of file?

I would like to remove empty lines from beginthe beginning and the end of file, but not remove empty lines between non-empty lines in the middle. I think sed or awk would be the solution.

Source:

1:
2:
3:line1
4:
5:line2
6:
7:
8:

Output:

1:line1
2:
3:line2

How to remove empty lines from begin and end of file?

I would like to remove empty lines from begin and the end of file, but not remove empty lines between lines. I think sed or awk would be the solution.

Source:

1:
2:
3:line1
4:
5:line2
6:
7:
8:

Output:

1:line1
2:
3:line2

How to remove empty lines from beginning and end of file?

I would like to remove empty lines from the beginning and the end of file, but not remove empty lines between non-empty lines in the middle. I think sed or awk would be the solution.

Source:

1:
2:
3:line1
4:
5:line2
6:
7:
8:

Output:

1:line1
2:
3:line2
Notice added Reward existing answer by Gordon
Bounty Started worth 50 reputation by Gordon
Tweeted twitter.com/StackUnix/status/1195808901909929989
Became Hot Network Question
added 46 characters in body
Source Link
Feriman
  • 1.1k
  • 1
  • 11
  • 16

I would like to remove empty lines from begin and the end of file, but not remove empty lines between lines. I think sed or awk would be the solution.

Source:

1:
2:
3:line1
4:
5:line2
6:
7:
8:

Output:

1:line1
2:
3:line2

I would like to remove empty lines from begin and the end of file, but not remove empty lines between lines.

Source:

1:
2:
3:line1
4:
5:line2
6:
7:
8:

Output:

1:line1
2:
3:line2

I would like to remove empty lines from begin and the end of file, but not remove empty lines between lines. I think sed or awk would be the solution.

Source:

1:
2:
3:line1
4:
5:line2
6:
7:
8:

Output:

1:line1
2:
3:line2
Source Link
Feriman
  • 1.1k
  • 1
  • 11
  • 16

How to remove empty lines from begin and end of file?

I would like to remove empty lines from begin and the end of file, but not remove empty lines between lines.

Source:

1:
2:
3:line1
4:
5:line2
6:
7:
8:

Output:

1:line1
2:
3:line2