aloha
aloha

Reputation: 4774

how to read a file in bash and create directories

I have a txt file of the form:

Billy-1b
Jim-1b
Kelly-1b

The txt file is called names.dat and is made up of 160 rows. I want to read the file and create a directory of each entry. Following the above example, I should have in my working directory 3 directories: Billy-1b Jim-1b and Kelly-1b. I am new to bash scripting. Thanks!

Upvotes: 1

Views: 983

Answers (2)

SLePort
SLePort

Reputation: 15461

You can loop over lines with read :

while read line; do 
  mkdir "$line"
done < names.dat

You'll have the same result with :

< names.dat xargs -L 1 mkdir

Upvotes: 2

anubhava
anubhava

Reputation: 785058

You can use xargs with mkdir like this:

xargs mkdir -p < names.dat

Upvotes: 4

Related Questions