I have a large text file that is corrupted in the middle When I attempt to read this file, say find the number of lines using 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
So I have thought about using tail command to print all that comes after this corrupted line, and join the output with all that comes before it. The tail command works fine by default, as it starts reading the file from the end of this file, so it can print the very end of this file without problems. But the problem is that, I do not know how many lines this file has. So if I try to skip all the lines before the corruption point using tail, I get:
person@terminal> tail -n +301 file.txt > after_error.txt
tail: error reading `file.txt': Input/output error
Which means that although tail can read the file starting from, of course, the end of a file, it still reads from the start of the file if I tell it to skip the first N lines.
My question is, how would I print all lines after my corruption point? I am also more than happy to know if there are other ways to salvage this file.
Try
strings file.txt
or
cp file.txt /otherPartition/file.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.