Просто небольшой тест с моей стороны, я надеюсь, что комментарии объяснят, что я сделал. Я предполагаю Баш.
По сути, поиск в Google «bash read csv file» помог мне. Остальное на самом деле просто некоторая логика if else и основные команды.
#!/usr/bin/env bash
OLDIFS=$IFS # store old delimiter for csv files
IFS=" | " # set delimiter of csv file
# attempt to get the filename of the only csv file in the current folder
# doesn't work if there are multiple csv files -> look into fuzzy finder or demenu for example
# doesn't work if csv file doesn't exist in current directory
# of course you can read the filename from command line with read command
# ls | grep *.csv might be useful to get all names of csv files in current directory
filename=$(ls | grep *.csv) # store output of command pipe in filename
echo "$filename" # debug, to see what is stored in $filename
while read f1 f2 f3 # read csv file, each line, 3 fields per line
do
# debug, echo each field
echo "field 1 is: $f1"
echo "field 2 is: $f2"
echo "field 3 is: $f3"
echo ""
echo "does $f2 exist?"
[ -d $f2 ] && echo "yes" || echo "no" # really just a short if else, in case you don't know this one
if [ ! -d $f2 ]; then # if directory in second column of csv doesn't exist
echo "creating directory"
mkdir -p $f2 # -p creates necessary parent directories if they don't exist
fi
echo "copying $f3 to $f2/$f3"
cp $f3 $f2/$f3 # copying doesn' force you to move files for testing, replace with move
done < $filename
# script never reaches this point if anything before fails
# if you want to use this script more often you should think about a way to reliably reset $IFS
IFS=$OLDIFS # reset delimiter
Мой CSV-файл:
whatever number | /existing_path/nonexisting_path/move_stuff_here | testfile.txt
testfile.txt должен существовать в вашем текущем рабочем каталоге, чтобы это работало.
Несуществующий _путь просто показывает mkdir -p.
Первые два символа в хеше — это соль. openssl passwd
должна иметь соль, и она всегда будет длиной 2 символа, ни больше, ни меньше.
Таким образом, в случае YY9E0oGqqamCM
и csL9dpD2Iy3H2
, YY
и cs
являются соответствующими солями.
$ openssl passwd -salt YY testing
YY9E0oGqqamCM
$ openssl passwd -salt cs testing
csL9dpD2Iy3H2