Восстановить шестнадцатеричный дамп звездочки с исходным содержимым

Оболочка расширяет выражение перед его выполнением rm, и это расширение не относится к команде, поэтому, если вы сделаете:

echo *20180626_1*

Тогда первое, что будет отображено, будет первым, что оболочка передаст в rm. Порядок не случайный, он алфавитный. На справочной странице bash:

After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern.

0
06.04.2020, 20:43
2 ответа

Попробуйте

awk '
/^\*/   {GAP = 1                                # check if action needed
         next                                   # don''t print, proceed to next line
        }
GAP     {TGT = sprintf ("%d", "0x" $1) + 0      # if action, calculate the end target
         do     {printf "%07x %s\n", L1, L0     # loop printing identical lines
                 L1 += 16                       # increment the first field
                }
         while (TGT > L1)                       # until target reached
         GAP = 0                                # reset action flag
        }
        {L1 = sprintf ("%d", "0x" $1) + 16      # save "to come" first field
         L0 = $0                                # and rest of line
         sub ("^" $1 FS, _, L0)
        }
1                                               # print input line
' file2
0000000 6161 6161 6161 6161 6161 6161 6161 6161
0000010 6161 6161 6161 6161 6161 6161 6161 6161
0000020 6161 6261 6262 6262 6262 6262 6262 6262
0000030 6262 6262 6262 6262 6262 6262 6262 6262
0000040 6262 6262 6262 6262 6262 6262 6262 6262
0000050 6262 6262 6262 6262 6262 6262 6262 6262
0000060 6262 6262 6262 6262 6262 6262 6262 6262
0000070 6262 6262 6262 6262 6262 6262 6262 6262
0000080 6262 6262 6262 6262 6262 6262 6262 6262
0000090 6262 6262 6262 6262 6262 6262 6262 6262
00000a0 6262 6262 6262 6262 6262 6262 6262 6262
00000b0 000a
00000b1
2
28.04.2021, 23:18

@RudiC Большое спасибо. Ваш скрипт работает сawk(original-awkmawk, но не с gawk. Уточните заранее, кто из них разработчик и чья версия. Вы также можете использовать namei /usr/bin/awk. Некоторые дистрибутивы Linux / *BSD могут включать любую его версию и быть символической ссылкой на любую другую.

Часто 'awk' является просто символической ссылкой на gawk, оригинальный -awk или mawk.

hexdump.exe random.dat | gawk '
/^\*/   {GAP = 1                                # check if action needed
         next                                   # don''t print, proceed to next line
        }
GAP     {TGT = sprintf ("%d", "0x" $1) + 0      # if action, calculate the end target
         do     {printf "%07x %s\n", L1, L0     # loop printing identical lines
                 L1 += 16                       # increment the first field
                }
         while (TGT > L1)                       # until target reached
         GAP = 0                                # reset action flag
        }
        {L1 = sprintf ("%d", "0x" $1) + 16      # save "to come" first field
         L0 = $0                                # and rest of line
         sub ("^" $1 FS, _, L0)
        }
1                                               # print input line
'
0000000 6161 6161 6161 6161 6161 6161 6161 6161
0000010 6161 6161 6161 6161 6161 6161 6161 6161
0000020 6161 6261 6262 6262 6262 6262 6262 6262
0000030 6262 6262 6262 6262 6262 6262 6262 6262
0000010 6262 6262 6262 6262 6262 6262 6262 6262
00000b0
hexdump.exe data2.dat | gawk '
> /^\*/   {GAP = 1                                # check if action needed
>          next                                   # don''t print, proceed to next line
>         }
> GAP     {TGT = sprintf ("%d", "0x" $1) + 0      # if action, calculate the end target
>          do     {printf "%07x %s\n", L1, L0     # loop printing identical lines
>                  L1 += 16                       # increment the first field
>                 }
>          while (TGT > L1)                       # until target reached
>          GAP = 0                                # reset action flag
>         }
>         {L1 = sprintf ("%d", "0x" $1) + 16      # save "to come" first field
>          L0 = $0                                # and rest of line
>          sub ("^" $1 FS, _, L0)
>         }
> 1                                               # print input line
> '
0000000 6161 6161 6161 6161 6161 6161 6161 6161
0000010 6161 6161 6161 6161 6161 6161 6161 6161
0000020 6161 6261 6262 6262 6262 6262 6262 6262
0000030 6262 6262 6262 6262 6262 6262 6262 6262
0000010 6262 6262 6262 6262 6262 6262 6262 6262
00000b0 000a
00000b1
1
28.04.2021, 23:18

Теги

Похожие вопросы