Skip to content
Advertisement

sed for print two different word alernatively

I have a requirement to print two different words in alternative white spaces in the file.

For example,

JavaScript

The above scenario, I want print ab and /ab alternatively like below:

JavaScript

*I want this one by one in a line by line format(Not horizontal format).*I know sed 's|^[[:blank:]]*$|</ab>|' this command is almost near to my case. But I don’t know how to apply this. Please, someone, help me.

Advertisement

Answer

If you are ok with awk then following may help you here.

JavaScript

In case you need to save output into Input_file itself then append > temp_file && mv temp_file Input_file in above code too.

Advertisement