"tail" of a binary based on line location using bash?

I have a bunch of binary files, each of which contains an embedded line closer to the end of the file, but in different places (happens only once in each file). I need to extract part of the file, starting from the line to the end of the file, and upload it to a new file.

eg. If the contents of the file are "AWREDEDEDEXXXERESSDSDS" and the line of interest is "XXX", then the part of the file I need is "XXXERESSDSDS".

What is the easiest way to do this in bash?

+3
source share
6 answers

I came up with this solution:

ls -1 *.bin | xargs strings -n4 --radix=d -f | grep "string" | awk '{sub(/:/, ""); print $2 " " $1 " " $1".";}' | xargs -l1 split -b && rm *.aa

ls -1 *.bin "bin"

xargs strings -n4 --radix = d -f

grep "string" , "string" ( )

awk '{sub (/:/, "); print $2" "$1" "$1".";} ' , , , ( split

xargs -l1 split -b split , awk,

rm *.aa . "aa" - .

, , // , .

0

PERL , . , . Bash , PERL , .

+1

, . .

script tail.sh :

#!/bin/sh
dd bs=1 if=$1 of=$2 skip=`grep --binary-files=text -m1 -b -o $3 $1 | cut -d ':' -f 1 | head -1`

tail.sh INPUTNAME OUTPUTNAME PATTERN

p.s: grep

+1

strings grep?

.

strings -n 3 myfilename | grep XXX
0
 strings -n3 file_binary | awk '/XXX/{gsub(/.*XXX/,"");print}'
0

:

grep -ao string.* filename

, .

grep -ao string.* filename > binary.out

Or skip it through hexdumpor similar for testing:

grep -ao string.* filename | hd
-1
source

Source: https://habr.com/ru/post/1739152/


All Articles