I want to split all the text files in a directory into 2 equal halves for each file. I tried the code below but it doesn't work.
我想将目录中的所有文本文件拆分为每个文件的两个相等的一半。我尝试了下面的代码,但它不起作用。
d=2
for file in /home/user1/Documents/files/*.txt; do
l=$(wc -l < "$file") #was l= wc $file | awk {'print $1'}
echo $l
sp=$((l/d)) #was sp = $((l/d))
echo $sp
split -l $sp $file $file.
done
1 个解决方案
#1
1
This line
这条线
l= wc $file | awk {'print $1'}
should be
应该
l=$(wc -l < "$file")
#1
1
This line
这条线
l= wc $file | awk {'print $1'}
should be
应该
l=$(wc -l < "$file")