【问题标题】:A bash script to split a data file into many sub-files as per an index file using dd一个 bash 脚本,用于根据索引文件使用 dd 将数据文件拆分为多个子文件
【发布时间】:2017-11-14 01:25:52
【问题描述】:

我有一个包含许多联合文件的大型数据文件。 它有一个单独的索引文件,具有该文件名,数据文件中每个文件的开始+结束字节。 我在创建 bash 脚本以将大文件拆分为 1000 个子文件时需要帮助。

数据文件:fileafilebfilec 等

索引文件:

文件名.png3049

文件夹\文件名2.png6136.

我猜这需要遍历索引文件的每一行,然后使用 dd 将相关字节提取到文件中。也许一个繁琐的部分可能是文件夹结构括号是 windows 风格而不是 linux 风格。

非常感谢任何帮助。

while read p; do

  q=${p#*<}
  startbyte=${q%>*}
  endbyte=${q#*>}
  filename=${p%<*}
  count=$(($endbyte - $startbyte))


toprint="processing $filename startbyte: $startbyte endbyte: $endbyte count: $c$
echo $toprint

done <indexfile

【问题讨论】:

  • 到目前为止:同时阅读 p; do echo $p q=${p#**} endbyte=${q#*>} filename=${p%
  • 把代码放在问题里,cmets里的代码很糟糕!
  • 谢谢 Nic3500,完成

标签: bash file split dd


【解决方案1】:

解决了 :-) 仅供参考:

while read p; do

#sort out variables
  q=${p#*<}
  startbyte=${q%>*}
  endbyte=${q#*>}
  filename=${p%<*}
  count=$(($endbyte - $startbyte))


#let it know we're working
toprint="processing $filename startbyte: $startbyte endbyte: $endbyte count: $c$
echo $toprint

if [[ $filename == *"/"* ]]; then
  echo "have found /"


directory=${filename%/*}


#if no directory exists, create it
if [ ! -d "$directory" ]; then
  # Control will enter here if $directory doesn't exist.
echo "directory not found - creating one"
mkdir ~/etg/$directory
fi

fi

dd skip=$startbyte count=$count if=~/etg/largefile of=~/etg/$filename bs=1

done <indexfile

【讨论】:

    猜你喜欢
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 2012-09-13
    • 1970-01-01
    • 2012-07-04
    • 2011-12-25
    相关资源
    最近更新 更多