What does the regex '/^$/d' mean?

regex, unix

Solution

/^$/d


/ - start of regex
^ - start of line
$ - end of line
/ - end of regex
d - delete lines which match

So basically find any line which is empty (start and ending points are the same, e.g. no chars), and delete them.

Problem

I was trying to remove blank lines in a file using bash script. Now when i was searching in the INTERNET, i came across two variations of it. In one, we can directly modify the source file and in the other we can store the out put in another file . Here are the code snippets : ``` sed -i '/^$/d' fileName.txt sed '/^$/d' fileName.txt > newFileName.txt ``` What i could not understand is how the regex '/^$/d' can be interpreted as blank lines. I am afraid i am not good in regex . Can some one explain me this one ? Also is there some other way to do it ?

Original source