Let's say I have an input file looking like:
ID1
1 5
6 8
ID2
1 4
5 7
I'm trying to formulate a loop that can combine these actions:
- If the line begins with a letter: replace the '\ n' after a field containing characters with a '\ t' (sed 's / \ n / \ t / g' )
- If the line begins with a number: replace every '\ t' and '\ n' with a comma (sed 's / \ t /, / g; s / \ n /, / g ') EXCEPT if the next line begins with a letter (sed 's / \ t /, / g')
Expected output:
ID1 1, 5, 6, 8
ID2 1, 4, 5, 7
This is what I tried so far (but I have no idea of how I could format it properly) :
sed '$1 ~ /^[A-Z]|^[1-9]/ {if ~ /^[A-Z] 's/\n/\t/g'; else if ~ /^[1-9] 's/\n/,/g'}'
Any help would be appreciated Thanks in advance