I have a text file that is organized as follows:Group 1asdsdsdsdf.html  jeffxcvxcvxcvx.html  bobvrgeiuvhif.html  sueGroup 2iwdowijdoi.html  marypokpompojm.html  dougndkjfsjfbs.html  lisaI need  a bash script that creates a directory named after each group. And then a text file inside named for each person in that group with their corresponding link on the first line.I have managed to be able create the directories, the named text files, and a file with only the links. But I don't know how to echo each link into each name file or how to sort them by group.I'm sure there are better ways to accomplish the small amount that I have.#!/bin/bashgrep Group list.txt > groupsgrep -v Group list.txt > links_nameswhile read file; do mkdir ${file}; done < groupswhile read line; do export name=`echo $line | awk '{print $2}'`touch $name; done < links_nameswhile read line; do export link=`echo $line | awk '{print $1}'`echo $link >> links ; done < links_namesrm {groups,links_names,links}
Bash script to echo the first positional of each line into file with name of the second
bash;awk;scripting;grep
With awk:awk '/^Group/{g=$0; system(mkdir \g\); next} g&&$0{print $1 >g/$2}' file/^Group/ if the line starts with the string Group...g=$0 set the variable g to the group name, for example Group 1.system(...) call the command mkdir with the system function to create that directory (notice the additional quotes to deal with spaces in group names).g&&$0 if the variable g is defined and the line is not empty...print $1 >g/$2 write the value in the first field $1 (the link) to a file in the directory g name by the value of the second field $2 (the name).The test:$ cat Group\ 2/dougpokpompojm.html