grep output to build folders with mkdir

Discussion in 'Command Line' started by Getut, Jul 17, 2014.

  1. Getut

    Getut New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    I have grep output that give me lines of text that I want to use as subfolder names and create the folders with mkdir. The grep portion is working and giving me the output I need. It is basically a string that exists before the first and only comma in each line of a text file.

    Code:
    grep -o '^[^,]*' textfile
    How can I iterate through those lines and build folders.. pseudo code below:

    mkdir -p rootfolder/(line1 of grep output)
    mkdir -p rootfolder/(line2 of grep output)


    etc.
  2. WharfRat

    WharfRat Member

    Messages:
    34
    Likes Received:
    11
    Trophy Points:
    8
    Pipe the output of grep to a while loop,


    Code:
    grep -o '^[^,]*' textfile|while read n;do mkdir "$n";done

    Good luck ;)

Share This Page