Home > Back-end >  Bash - format .txt file into pover pivot form
Bash - format .txt file into pover pivot form

Time:07-15

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

CodePudding user response:

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

  • Related