[英]Skip the first N lines and print the rest of the file, given there is a file corruption in the middle of the file
我有一個中間損壞的大文本文件,當我嘗試讀取此文件時,說使用awk查找行數:
person@terminal> awk 'END{print NR}' file.txt
awk: (FILENAME=file.txt FNR=300) fatal: error reading input file `file.txt': Input/output error
因此,我考慮過使用tail命令打印此行之后的所有內容,並將輸出與該行之前的所有內容結合在一起。 默認情況下,tail命令正常運行,因為它從該文件的末尾開始讀取文件,因此它可以打印該文件的末尾而不會出現問題。 但是問題是,我不知道該文件有多少行。 因此,如果我嘗試使用tail跳過損壞點之前的所有行,則會得到:
person@terminal> tail -n +301 file.txt > after_error.txt
tail: error reading `file.txt': Input/output error
這意味着盡管tail可以從文件的末尾開始讀取文件,但是如果我告訴它跳過前N行,它仍將從文件的開頭開始讀取。
我的問題是,如何在損壞點之后打印所有行? 我也很高興知道是否還有其他方法可以保存此文件。
嘗試
strings file.txt
要么
cp file.txt /otherPartition/file.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.