Issue
I have tried two different sed commands against a text file called "file1.txt". I have received the same result or output. What I don't understand is the meaning or use of "G" option! I have searched online, but I couldn't find a good answer!
Here are two commands:
sed 'G' file1.txt
sed '/^$/d;G' file.txt
Both commands give the same output! They create a one line gap between each line in the text file! I know that'^$' refers to line containing nothing, but what does 'G' do. For example if I put 'd' instead of 'G' all blank lines will be deleted!
Solution
According to the man sed
:
g
Replace the contents of the pattern space with the contents of the hold space.
G
Append a newline to the contents of the pattern space, and then append the contents of the hold space to that of the pattern space.
Answered By - Tom Ruh Answer Checked By - Katrina (WPSolving Volunteer)