1) first, I added a newline to mark each record sed -i 's/h/h\n/g' infile ,
2) then, I added the the tab delimiter sed -i '/.$/N; s/.\n/\t/' infile It works but strangely, not everywhere. This is the output I get
In your second script the N command does join a current pattern space with the next line; however the s command causes the (updated) pattern space to be printed out. Essentially, you join pairs of lines.
My recommendation would be to use a hold buffer, and careful addressing like this:
# Notice the negation. Any line not matching is appended to the hold buffer
# Got the end of record. Append it to the hold buffer...
# ...copy the hold buffer into the pattern space...
# ...replace newlines with tabs...
# ...print out the desired result
# Finally, clear the pattern space and place an empty line in the hold buffer
# for the next iteration.