Bash – format .txt file into pover pivot form

Issue

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

Solution

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).

Answered By – Barmar

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published