Piyaput Boonpume
Piyaput Boonpume

Reputation: 73

What does this mean in Linux sed '$a\' a.txt

I have this line in my Linux shell script

sed '$a\' < file_a.txt

Afraid to remove it from the code and cannot find out what it is for.

Upvotes: 7

Views: 1144

Answers (1)

Thomas Baruchel
Thomas Baruchel

Reputation: 7517

It makes sure the output will end with a newline; see:

echo -ne test | sed '$a\'
# same output as:
echo test | sed '$a\'

As you can see with the previous code, a carriage return isn't added in the second example but one is added in the first example. Of course, if you remove the sed part, the output will be different since the first echo statement has no carriage return.

Upvotes: 6

Related Questions