简体   繁体   中英

How to create directories automatically in linux?

I am having a file named temp.txt where inside this file it contains the following content https://abcdef/12345-xyz

https://ghifdfg/5426525-abc

I need to create a directories automatically in linux by using only th number part from each line in the file. So the output should be something like 12345 and 5426525 directories created.

Any approach on how to do this could be helpful.

This is the code that i searched and got from internet,wherein this code, new directories will be created by the file name that starts with BR and W0 .

for file in {BR,W0}*.*; do
dir=${file%%.*}
mkdir -p "$dir"
mv "$file" "$dir"
done

Assuming each URL is of the form

http[s]://any/symbols/some_digits-some_letters

Then you indeed could use the simple prefix and suffix modifiers in shell variable expansion.

${x##*/} expands to the suffix part of x that starts after the last slash / .

${y%%-*} expands to the prefix part of y before the first - .

while read x ; do
  y=${x##*/} 
  z=${y%%-*} 
  mkdir $z
done < temp.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM