Using dd for retrieval of data
Hello,
I did post about how to use dd searching for strings, but it may have got lost in the ether.
Anyway, I cannot find any usage of using dd in an intelligent way to find strings of data, then save data before and after the string to a text file on a different drive.
There are a few variables that I do know, that there is a string with the exact string 'apply-online-for-student-finance' that I want to find. I know the file is 206kb, and also that the string is the last thing I wrote to the file and then saved it, so there will be 206kb data preceding that string.
So I'd be using if=/dev/hda1 of=/dev/hda2/newfile.txt
and for every instance of 'mystring'
to do a new file, which would be newfile1.txt, newfile2.txt, newfilen.txt, etc.
I was thinking, could I get 2 variables a and b, then allocate 206k to each sequentially, overwriting each one with the next lot of 206k of data to read in, and if 'mystring' is not in a then search for it in b, if it is not located in b then get the next lot of data and allocate it to a, then if it is in a then add b then a to the text file, which would be how I can be sure of getting the 206k of data previous to my string, and continue until the end of the disk or partition.
So to put that in a loop, is also a challenge, and I am new to this, but the logic would be something like:
while data exists on $driveA #the partition we are searching
if !a then allocate next 206k to b, then if !b then allocate next 206k to a;
As a script, I could pass a few variables to it, like:
ddscript 'mystring' if_area of_area file_size
Would the logic work? Any answers would have gratuitous praise.
Thanks
|