Разделение большого файла на несколько?

Наконец выяснилось, что с этим не так. Совершал действительно глупую ошибку! Спасибо @cas за то, что подтолкнули меня к этому.

Выполнил # / usr / bin / env python3.4 вместо #! / Usr / bin / env python3.4 .

Во-вторых, мне пришлось указать абсолютный путь, когда сценарий usr_check.py пытался подключиться к базе данных user_base.db .

Это решило проблему для меня.

0
20.06.2018, 06:17
3 ответа

Простой пример, проверенный с помощьюbash:

#! /bin/bash 
# first sub file index
j=1
# first line after header
i=4
# 50 lines per sub file
lines=50
# lines in file to split
total_lines=$(cat file_to_cut | wc -l)

while [ $i -lt $total_lines ]
do 
    # copy header
    head -n 3 example > sub_file_$j
    # copy data
    tail -n +$i fite_to_cut | head -n $lines >> sub_file_$j
    # prepare next file
    j=$((j+1))        
    # prepare next line to read
    i=$((i+$lines))
done
0
28.01.2020, 02:42

Предполагая, что вы хотите bsubкаждый сценарий, соответствующий шаблону "$testbench_dir"/cell/delay_*_*.sp.py, вы можете заменить свой сценарий следующим:

#!/bin/sh

config_dir=/proj/ABC/users/nhannguyen/work/verif/qc/input
testbench_dir=/proj/ABC/users/nhannguyen/work/verif/qc/testbench/TT_p025c

for py in "$testbench_dir"/cell/delay_*_*.sp.py; do
    bsub "$py" -c "$config_dir/sim.config.py" -m 1
done

Это /bin/sh, а не cshсценарий, но это не имеет значения.

Если вам нужно убедиться, что скрипты выполняются в определенном порядке (вышеперечисленное отсортирует файлы скриптов в лексикографическом порядке ), затем выполните двойной цикл:

#!/bin/sh

config_dir=/proj/ABC/users/nhannguyen/work/verif/qc/input
testbench_dir=/proj/ABC/users/nhannguyen/work/verif/qc/testbench/TT_p025c

maxi=300   # the largest number I in delay_I_J.sp.py
maxj=3     # the largest number J in delay_I_J.sp.py

i=0
until [ "$i" -gt "$maxi" ]; do
    j=0
    until [ "$j" -gt "$maxj" ]; do
        bsub "$testbench_dir/cell/delay_${i}_${j}.sp.py" -c "$config_dir/sim.config.py" -m 1
        j=$(( j + 1 ))
    done
    i=$(( i + 1 ))
done

Если вы хотите, чтобы скрипт отправлял задания только пакетами по 50 штук и имел возможность указать в командной строке, какой пакет отправлять, например,.

./script 3

(запустит пакет 3, т. е. задания 100 -149)

#!/bin/sh

batch=$1

if [ -z "$batch" ]; then
    printf 'Usage: %s batchnumber\n' "$0" >&2
    exit 1
fi

bstart=$(( (batch - 1)*50 ))
bend=$(( batch*50 - 1 ))

printf 'Submitting batch %d (jobs %d to %d)\n' "$batch" "$bstart" "$bend"

config_dir=/proj/ABC/users/nhannguyen/work/verif/qc/input
testbench_dir=/proj/ABC/users/nhannguyen/work/verif/qc/testbench/TT_p025c

count=0
for py in "$testbench_dir"/cell/delay_*_*.sp.py; do
    if [ "$count" -gt "$bend" ]; then
        break
    fi

    if [ "$count" -ge "$bstart" ]; then        
        bsub "$py" -c "$config_dir/sim.config.py" -m 1
    fi

    count=$(( count + 1 ))
done
0
28.01.2020, 02:42
#!/bin/bash
# step 1: Remove the header:
tail -n +4./bigfile.csh > bigfile_without_header.csh

# step 2: Split the file:
split -d -l 1000 --additional-suffix=.csh./bigfile_without_header.csh split-

# step 3: Add the header back to each file:
HEADER='#!/bin/csh\nset config_dir = /proj/ABC/users/nhannguyen/work/verif/qc/input\nset testbench_dir = /proj/ABC/users/nhannguyen/work/verif/qc/testbench/TT_p025c\n'
sed -i "1s,^,$HEADER," split-*.csh
1
28.01.2020, 02:42

Теги

Похожие вопросы