2016-04-04 9 views
1

我想在每個輸出文件的16行中分割一個大文件。我可以使用split -l 16 q1.txt new來做到這一點。但我想輸出到像ratio1.txt,ratio2.txt,...... ratio100.txt等,所以我想:split -l 16 -d --additional-suffix=.txt q1.txt ratio在mac osx上使用分割函數重命名輸出文件

然後我得到這個錯誤信息在我的Mac:

split: illegal option -- d 
usage: split [-a sufflen] [-b byte_count] [-l line_count] [-p pattern] 
      [file [prefix]] 

任何人都可以請幫助我獲得所需的輸出文件字符串?謝謝。

回答

3

如果您檢查man split,您會發現該版本不支持參數--additional-suffix=SUFFIX

達到什麼我知道你想你需要一個Automator的腳本或shell腳本,例如:

#!/bin/sh 

DONE=false 
until $DONE; do 
    for i in $(seq 1 16); do 
    read line || DONE=true; 
    [ -z "$line" ] && continue; 
    lines+=$line$'\n'; 
    done 
    ratio=${lines::${#lines}-10} 
    (cat "Ratio"; echo "$ratio .txt";) 
    #echo "--- DONE SPLITTING ---"; 
    lines=; 
done < $1 
+0

感謝。我看到人分裂,但無法弄清楚如何解決這個問題。 – user3389597

+0

你可以試試這樣的腳本: 'nano scriptname.sh'會打開編輯器,粘貼腳本,然後'chmod a + x scriptname.sh'使它可執行,然後用'./scriptname'調用它。 sh q1.txt' –

+0

謝謝。這很有幫助 – user3389597

相關問題