Skip to content
Advertisement

Bash – format .txt file into pover pivot form

txt file called without_Commas.txt. The content looks like this:

User1 = dsa jhg asfd
User2 = ikjl retzg
User3 = ölkjdshf
...
User400 = gt345 234gt 7fgd zhju ertzui 

I need to format this data to look like this:

User1   dsa 
User1   jhg
User1   asdf
User2   ikjl
User2   retzg
User3   ölkjdshf
...
User400   gt345
User400   234gt
User400   7fgd
User400   zhju
User400   ertzui

Is there a way to do this?

Kind Regards Elias

Advertisement

Answer

awk '{for (i = 3; i <= NF; i++) print $1, $i}' without_Commas.txt > output.txt

On each line, this loops over all the field numbers starting with the third field. Then it prints the first field ($1) followed by the current field in the loop ($i).

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement