I am having below data in a text file
[abcd]
sgsgdh
shshdhd
shdhdhd
[defg]
sgshdhd
shshdjd
shshdhd
shehddkd
shejdjd
[jkhl]
sgshdjdj
shejdjr
shshdhd
sgehdjd
shehdjjd
output
[abcd] : shshdhd
[defg] : shshdhd
[defg] : shshdhd
and so on
I am having below data in a text file
[abcd]
sgsgdh
shshdhd
shdhdhd
[defg]
sgshdhd
shshdjd
shshdhd
shehddkd
shejdjd
[jkhl]
sgshdjdj
shejdjr
shshdhd
sgehdjd
shehdjjd
output
[abcd] : shshdhd
[defg] : shshdhd
[defg] : shshdhd
and so on
awk 'BEGIN {RS = ""; FS = "\n"; OFS = " : "} {print $1, $2}' file
[abcd] : sgsgdh
[defg] : sgshdhd
[jkhl] : sgshdjdj
If you want the blank lines in the output, add ORS = "\n\n" to the BEGIN block