2016-05-31 129 views
0

我有一系列編號的子目錄,可能包含或不包含zip文件,並在這些zip文件中是我需要的一些單行.txt文件。是否可以使用find和unzip -p的組合在同一輸出行中列出文件路徑和單行內容?我想將結果保存爲.txt文件並將其導入到excel中以便處理。找到一個zip文件,打印路徑和zip內容

從主目錄,我可以順利地找到並輸出了一行:

find . -name 'file.zip' -exec unzip -p {} file.txt \; 

我如何查找輸出(即文件路徑)前綴,這個解壓命令的輸出?理想情況下,我希望文本文件的每一行類似於:

./path/to/file1.zip "Single line of file1.txt file" 
./path/to/file2.zip "Single line of file2.txt file" 

等等。誰能提供一些建議?除了簡單的命令之外,我對linux命令行不太瞭解。

謝謝。

回答

0

把所有要執行到一個shell腳本,然後使用exec功能調用shell腳本的代碼,即

cat finder.bash 
#!/bin/bash 

printf "[email protected] : " # prints just the /path/to/file/file.zip 
unzip -p "[email protected]" file.txt 

現在,得到那個工作,你可以把它通用於稍後再通過file.txt以外的其他人。

使腳本可執行

chmod 755 finder.bash 

find調用它。即

find . -name 'file.zip' -exec /path/to/finder.bash {} \; 

(我沒有一個簡單的方法來測試這個,所以回覆評論與錯誤信息)。

相關問題