Unable to replace Unicode characters with sed or vim - vim

I have a file with what I believe to be a unicode type and would like to remove them with sed or some other unix utility. I have tried few options and for some reason unable to remove those characters. Test cases shown with single line (head -n1)
Attempt 1:
> head -n1 file1.txt | hexdump -C # Hexdump line 1
output:
00000000 47 72 6f 75 70 c2 a0 20 20 20 53 69 67 6e 61 6c |Group.. Signal|
00000010 c2 a0 6e 61 6d 65 c2 a0 20 20 20 20 20 20 20 20 |..name.. |
00000020 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
00000030 55 6e 69 74 c2 a0 20 74 79 70 65 c2 a0 44 65 73 |Unit.. type..Des|
00000040 63 72 69 70 74 69 6f 6e c2 a0 0d 0a |cription....|
0000004c
Now replace "c2 a0" above
> head -n1 file1.txt | sed 's/\xc2\xa0//g' | hexdump -C
or
> head -n1 file1.txt | sed 's/\x{c2a0}//g | hexdump -C
00000000 47 72 6f 75 70 c2 a0 20 20 20 53 69 67 6e 61 6c |Group.. Signal|
00000010 c2 a0 6e 61 6d 65 c2 a0 20 20 20 20 20 20 20 20 |..name.. |
00000020 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
00000030 55 6e 69 74 c2 a0 20 74 79 70 65 c2 a0 44 65 73 |Unit.. type..Des|
00000040 63 72 69 70 74 69 6f 6e c2 a0 0d 0a |cription....|
No replacements happend
Attempt 2: Using vim
vim file1.txt
:set nobomb
:set fileencoding=utf-8
:wq
Used sed again and no replacements happened. How do I replace or remove those characters (hex "c2a0")?

I finally ended up using Perl which successfully removed the unicode chars.
> perl -v
This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
> perl -pi -e 's/\x{c2}\x{a0}//g' file1.txt
> head -n1 file1.txt | hexdump -C
00000000 47 72 6f 75 70 20 20 20 53 69 67 6e 61 6c 6e 61 |Group Signalna|
00000010 6d 65 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |me |
00000020 20 20 20 20 20 20 20 20 20 20 55 6e 69 74 20 74 | Unit t|
00000030 79 70 65 44 65 73 63 72 69 70 74 69 6f 6e 0d 0a |ypeDescription..|
00000040

Related

strace does not show the complete write

Im trying to view the data being written to an HTTP socket using strace
However, although I have given -e write=all, I still cannot see all the data being written
strace -o /tmp/capture.log -p <pid> -e trace=all -e write=all -e read=all -f -tt
..
29620 16:09:14.723120 write(1899, "POST /task/native.wsdl HTTP/1.1\r"..., 210) = 210
29620 16:09:14.723319 write(1899, "<soap:Envelope xmlns:soap=\"http:"..., 450) = 450
What is strange is that, it shows the complete data during some other writes to other sockets
31145 16:09:28.110571 write(359, "POST /task/native.wsdl HTTP/1.1\r"..., 210) = 210
| 00000 50 4f 53 54 20 2f 74 61 73 6b 2f 6e 61 74 69 76 POST /task/nativ |
| 00010 65 2e 77 73 64 6c 20 48 54 54 50 2f 31 2e 31 0d e.wsdl HTTP/1.1. |
| 00020 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 .Content-Type: t |
| 00030 65 78 74 2f 78 6d 6c 3b 20 63 68 61 72 73 65 74 ext/xml; charset |
| 00040 3d 55 54 46 2d 38 0d 0a 41 63 63 65 70 74 3a 20 =UTF-8..Accept: |
| 00050 2a 2f 2a 0d 0a 53 4f 41 50 41 63 74 69 6f 6e 3a */*..SOAPAction: |
| 00060 20 22 22 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a ""..User-Agent: |
| 00070 20 41 70 61 63 68 65 20 43 58 46 20 32 2e 37 2e Apache CXF 2.7. |
| 00080 31 31 0d 0a 48 6f 73 74 3a 20 65 73 2d 73 76 63 11..Host: es-svc |
| 00090 73 2e 69 74 2e 61 74 74 2e 63 6f 6d 3a 37 30 30 s.it.att.com:700 |
| 000a0 33 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 4b 3..Connection: K |
| 000b0 65 65 70 2d 41 6c 69 76 65 0d 0a 43 6f 6e 74 65 eep-Alive..Conte |
| 000c0 6e 74 2d 4c 65 6e 67 74 68 3a 20 34 35 30 0d 0a nt-Length: 450.. |
| 000d0 0d 0a .. |
Can somebody please explain. Is it possible to get data from all writes
The strace -e write=a,b flag shows write syscalls for file descriptors numbered from a to b, and -e write=all shows write syscalls to all file descriptors.
What you're looking for is -e abbrev=none; see the manpage:
-e abbrev=set
Abbreviate the output from printing each member of large structures.
The default is abbrev=all. The -v option has the effect of abbrev=none.

how to extract a number from text file (or do a query on a site to get that number to bat file

I'm trying to write a bat file that would use output of https://www.feathercoin.com/netstats/
I need current network difficulty
I used curl to extract the contents of the webpage and findstr to write output of a string that contains difficulty to a file:
here's how file looks=
Current Block Number: В  1971095
Current Hashrate in Kh/s: В  2714249.165
Next retarget block number: В  1971096
Blocks to next retarget: В  1
Current difficulty: В  24.29714508
Expected next difficulty: В  26.496224436026
Time to retarget in second: В  34.366666666667
Total number of Feathercoins: В  182244280
in hex:
3C 68 31 3E 3C 2F 68 31 3E 3C 70 3E 43 75 72 72 65 6E 74 20 42 6C 6F 63 6B 20 4E 75 6D 62 65 72 3A 20 C2 A0 20 31 39 37 31 30 39 35 3C 62 72 20 2F 3E 43 75 72 72 65 6E 74 20 48 61 73 68 72 61 74 65 20 69 6E 20 4B 68 2F 73 3A 20 C2 A0 20 32 37 31 34 32 34 39 2E 31 36 35 3C 62 72 20 2F 3E 4E 65 78 74 20 72 65 74 61 72 67 65 74 20 62 6C 6F 63 6B 20 6E 75 6D 62 65 72 3A 20 C2 A0 20 31 39 37 31 30 39 36 3C 62 72 20 2F 3E 42 6C 6F 63 6B 73 20 74 6F 20 6E 65 78 74 20 72 65 74 61 72 67 65 74 3A 20 C2 A0 20 31 3C 62 72 20 2F 3E 43 75 72 72 65 6E 74 20 64 69 66 66 69 63 75 6C 74 79 3A 20 C2 A0 20 32 34 2E 32 39 37 31 34 35 30 38 3C 62 72 20 2F 3E 45 78 70 65 63 74 65 64 20 6E 65 78 74 20 64 69 66 66 69 63 75 6C 74 79 3A 20 C2 A0 20 32 36 2E 34 39 36 32 32 34 34 33 36 30 32 36 3C 62 72 20 2F 3E 54 69 6D 65 20 74 6F 20 72 65 74 61 72 67 65 74 20 69 6E 20 73 65 63 6F 6E 64 3A 20 C2 A0 20 33 34 2E 33 36 36 36 36 36 36 36 36 36 36 37 3C 62 72 20 2F 3E 54 6F 74 61 6C 20 6E 75 6D 62 65 72 20 6F 66 20 46 65 61 74 68 65 72 63 6F 69 6E 73 3A 20 C2 A0 20 31 38 32 32 34 34 32 38 30 0A
further i tried
FOR /f "usebackq tokens=1-10" %%I in ("b.txt") do (
SET I=%%I && SET J=%%J && SET K=%%K && SET L=%%L && SET M=%%M && CALL :ECHO %%I
)
That does not get me anywhere any suggestions on how to get current difficulty to a %%I would be appreciated!
If i can get feathercoin difficulty to a variable i'd be able to control which miner to use depending on the network difficulty of the feather coin thanks in advance!!!
I suggest following code for file b.txt being UTF-8 encoded and containing a non-breaking space on each line:
#echo off
for /F "tokens=1-3*" %%A in ('type "b.txt"') do (
if /I "%%A %%B" == "Current difficulty:" (
set "CurrentDifficulty=%%D"
goto HaveDifficulty
)
)
echo Upps, could not find current difficulty.
goto :EOF
:HaveDifficulty
echo Current difficulty is: %CurrentDifficulty%
The file b.txt is not processed directly by FOR line by line because FOR fails to correct process Unicode text files. Instead the command TYPE is used to output the content of this file in ANSI (or more precise in OEM) in a separate command process started by FOR in background with cmd /C and captured by FOR.
Each line of captured output not being empty or starting with a semicolon is split up by FOR into four substrings (tokens) using the default delimiters normal space and horizontal tab.
The first tab/space separated string is assigned to loop variable A which is on the line of interest the string Current. The second tab/space separated string difficulty: is assigned to next loop variable according to ASCII table which is B. The third string is the strange character being of no interest and assigned to loop variable C. And the fourth string is the rest of the line after tabs/spaces after third string which is on line of interest the string 24.29714508.
A case-insensitive IF condition is used to check if the first two substrings of current line concatenated with a space is Current difficulty:. If that condition is true, the right line is found in output of the file. For that reason the fourth string is assigned to environment variable CurrentDifficulty and the loop is exited without processing the other lines of captured output with a jump in batch file processing to a defined label.
It is expected by this batch file that the UTF-8 encoded file contains the bytes:
0000h: 43 75 72 72 65 6E 74 20 42 6C 6F 63 6B 20 4E 75 ; Current Block Nu
0010h: 6D 62 65 72 3A 20 C2 A0 20 31 39 37 31 30 39 35 ; mber:   1971095
0020h: 0D 0A 43 75 72 72 65 6E 74 20 48 61 73 68 72 61 ; ..Current Hashra
0030h: 74 65 20 69 6E 20 4B 68 2F 73 3A 20 C2 A0 20 32 ; te in Kh/s:   2
0040h: 37 31 34 32 34 39 2E 31 36 35 0D 0A 4E 65 78 74 ; 714249.165..Next
0050h: 20 72 65 74 61 72 67 65 74 20 62 6C 6F 63 6B 20 ; retarget block
0060h: 6E 75 6D 62 65 72 3A 20 C2 A0 20 31 39 37 31 30 ; number:   19710
0070h: 39 36 0D 0A 42 6C 6F 63 6B 73 20 74 6F 20 6E 65 ; 96..Blocks to ne
0080h: 78 74 20 72 65 74 61 72 67 65 74 3A 20 C2 A0 20 ; xt retarget:  
0090h: 31 0D 0A 43 75 72 72 65 6E 74 20 64 69 66 66 69 ; 1..Current diffi
00a0h: 63 75 6C 74 79 3A 20 C2 A0 20 32 34 2E 32 39 37 ; culty:   24.297
00b0h: 31 34 35 30 38 0D 0A 45 78 70 65 63 74 65 64 20 ; 14508..Expected
00c0h: 6E 65 78 74 20 64 69 66 66 69 63 75 6C 74 79 3A ; next difficulty:
00d0h: 20 C2 A0 20 32 36 2E 34 39 36 32 32 34 34 33 36 ;   26.496224436
00e0h: 30 32 36 0D 0A 54 69 6D 65 20 74 6F 20 72 65 74 ; 026..Time to ret
00f0h: 61 72 67 65 74 20 69 6E 20 73 65 63 6F 6E 64 3A ; arget in second:
0100h: 20 C2 A0 20 33 34 2E 33 36 36 36 36 36 36 36 36 ;   34.366666666
0110h: 36 36 37 0D 0A 54 6F 74 61 6C 20 6E 75 6D 62 65 ; 667..Total numbe
0120h: 72 20 6F 66 20 46 65 61 74 68 65 72 63 6F 69 6E ; r of Feathercoin
0130h: 73 3A 20 C2 A0 20 31 38 32 32 34 34 32 38 30 0D ; s:   182244280.
0140h: 0A ; .
But if the file does not even contain carriage return 0D and line-feed 0A, but is a single "line" with all the words and floating point numbers, the batch file above fails to extract the floating point number of current difficulty from this text file.
But the UTF-8 encoded b.txt contains in real the text:
Current Block Number:   1971095Current Hashrate in Kh/s:   2714249.165Next retarget block number:   1971096Blocks to next retarget:   1Current difficulty:   24.29714508Expected next difficulty:   26.496224436026Time to retarget in second:   34.366666666667Total number of Feathercoins:   182244280
The hexadecimal representation with file offset (left side) and Windows-1252 representation (right side) is:
0000h: 43 75 72 72 65 6E 74 20 42 6C 6F 63 6B 20 4E 75 ; Current Block Nu
0010h: 6D 62 65 72 3A 20 C2 A0 20 31 39 37 31 30 39 35 ; mber:   1971095
0020h: 43 75 72 72 65 6E 74 20 48 61 73 68 72 61 74 65 ; Current Hashrate
0030h: 20 69 6E 20 4B 68 2F 73 3A 20 C2 A0 20 32 37 31 ; in Kh/s:   271
0040h: 34 32 34 39 2E 31 36 35 4E 65 78 74 20 72 65 74 ; 4249.165Next ret
0050h: 61 72 67 65 74 20 62 6C 6F 63 6B 20 6E 75 6D 62 ; arget block numb
0060h: 65 72 3A 20 C2 A0 20 31 39 37 31 30 39 36 42 6C ; er:   1971096Bl
0070h: 6F 63 6B 73 20 74 6F 20 6E 65 78 74 20 72 65 74 ; ocks to next ret
0080h: 61 72 67 65 74 3A 20 C2 A0 20 31 43 75 72 72 65 ; arget:   1Curre
0090h: 6E 74 20 64 69 66 66 69 63 75 6C 74 79 3A 20 C2 ; nt difficulty: Â
00a0h: A0 20 32 34 2E 32 39 37 31 34 35 30 38 45 78 70 ;   24.29714508Exp
00b0h: 65 63 74 65 64 20 6E 65 78 74 20 64 69 66 66 69 ; ected next diffi
00c0h: 63 75 6C 74 79 3A 20 C2 A0 20 32 36 2E 34 39 36 ; culty:   26.496
00d0h: 32 32 34 34 33 36 30 32 36 54 69 6D 65 20 74 6F ; 224436026Time to
00e0h: 20 72 65 74 61 72 67 65 74 20 69 6E 20 73 65 63 ; retarget in sec
00f0h: 6F 6E 64 3A 20 C2 A0 20 33 34 2E 33 36 36 36 36 ; ond:   34.36666
0100h: 36 36 36 36 36 36 37 54 6F 74 61 6C 20 6E 75 6D ; 6666667Total num
0110h: 62 65 72 20 6F 66 20 46 65 61 74 68 65 72 63 6F ; ber of Featherco
0120h: 69 6E 73 3A 20 C2 A0 20 31 38 32 32 34 34 32 38 ; ins:   18224428
0130h: 30 ; 0
For such a file a different approach is needed to get the floating point number of Current difficulty. I suggest to use JREPL.BAT written by Dave Benham being stored in current directory on execution of the batch file posted below.
#echo off
set "CurrentDifficulty="
for /F %%I in ('jrepl.bat "^.*Current difficulty:[^0-9.]+([0-9.]+).*$" "$1" /M /F b.txt') do set "CurrentDifficulty=%%I"
if not defined CurrentDifficulty (
echo Upps, could not find current difficulty.
goto :EOF
)
echo Current difficulty is: %CurrentDifficulty%
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
for /?
goto /?
if /?
set /?
type /?

Hexdump -C but decimal instead of hex

centos 6.5 - running hexdump
$ hexdump -C filecsv
00000000 44 4f 53 2c 20 50 61 74 69 65 6e 74 2c 20 41 63 |DOS, Patient, Ac|
00000010 63 74 20 23 2c 20 4d 52 20 23 2c 20 54 69 6d 65 |ct #, MR #, Time|
Love this format but want hex to be converted to decimal
I have spent time looking but cannot find this?
hexdump supports specifying a format string via the -e command-line option, and it seems to be pretty flexible.
Example:
$ hexdump -C b.c
00000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e |#include <stdio.|
00000010 68 3e 0a 69 6e 74 20 6d 61 69 6e 28 29 7b 0a 20 |h>.int main(){. |
00000020 20 70 72 69 6e 74 66 28 22 68 65 6c 6c 6f 20 77 | printf("hello w|
00000030 6f 72 6c 64 5c 6e 22 29 3b 0a 20 20 72 65 74 75 |orld\n");. retu|
00000040 72 6e 20 30 3b 0a 7d 0a |rn 0;.}.|
00000048
$ hexdump -e'"%07.8_ax " 8/1 "%02x " " " 8/1 "%02x " " |"' -e'16/1 "%_p" "|\n"' b.c
00000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e |#include <stdio.|
00000010 68 3e 0a 69 6e 74 20 6d 61 69 6e 28 29 7b 0a 20 |h>.int main(){. |
00000020 20 70 72 69 6e 74 66 28 22 68 65 6c 6c 6f 20 77 | printf("hello w|
00000030 6f 72 6c 64 5c 6e 22 29 3b 0a 20 20 72 65 74 75 |orld\n");. retu|
00000040 72 6e 20 30 3b 0a 7d 0a |rn 0;.}.|
$ hexdump -e'"%07.8_ad " 8/1 "%03d " " " 8/1 "%03d " " |"' -e'16/1 "%_p" "|\n"' b.c
00000000 035 105 110 099 108 117 100 101 032 060 115 116 100 105 111 046 |#include <stdio.|
00000016 104 062 010 105 110 116 032 109 097 105 110 040 041 123 010 032 |h>.int main(){. |
00000032 032 112 114 105 110 116 102 040 034 104 101 108 108 111 032 119 | printf("hello w|
00000048 111 114 108 100 092 110 034 041 059 010 032 032 114 101 116 117 |orld\n");. retu|
00000064 114 110 032 048 059 010 125 010 |rn 0;.}.|
Not sure about how to reproduce that last line produced by -C.
See here for more details.

Meaning of bytes in BitTorrent protocol

I am going to try to write simple BitTorrent client. Of course I read http://wiki.theory.org/BitTorrentSpecification. I began by analyzing communication between two clients. I have problem with meaning of two fields - bold font in the following hexadecimal dump.
First packet send by Deluge to rTorrent:
00000000 13 |. | - protocol name length (1) - 0x13 = 19
00000000 42 69 74 54 6f 72 72 65 6e 74 20 70 72 6f 74 | BitTorrent prot| - protocol name (19)
00000010 6f 63 6f 6c |ocol |
00000010 00 00 00 00 00 18 00 05 | ........ | - reserved extension bytes (8)
00000010 ab 20 ef 66 | . .f| - info_hash (20)
00000020 c8 ee de 47 99 a2 75 40 20 75 ee 7b c6 4e 2f dd |...G..u# u.{.N/.|
00000030 2d 44 45 31 33 33 30 2d 42 6c 78 37 6c 69 7a 7e |-DE1330-Blx7liz~| - peer_id (20)
00000040 4a 54 2e 6a |JT.j| Deluge 1.3.3
Answer from rTorrent to Deluge:
00000000 13 |. | - protocol name length (1) - 0x13 = 19
00000000 42 69 74 54 6f 72 72 65 6e 74 20 70 72 6f 74 | BitTorrent prot| - protocol name (19)
00000010 6f 63 6f 6c |ocol |
00000010 00 00 00 00 00 10 00 00 | ........ | - reserved extension bytes (8)
00000010 ab 20 ef 66 | . .f| - info_hash (20)
00000020 c8 ee de 47 99 a2 75 40 20 75 ee 7b c6 4e 2f dd |...G..u# u.{.N/.|
00000030 2d 6c 74 30 43 39 30 2d b6 eb 22 ae 31 e3 89 90 |-lt0C90-..".1...| - peer_id (20)
00000040 2a 9b af a9 |*... | libTorrent (rakshasa) 0.12.9
00000040 00 00 00 6e | ...n | - message length? (4) - 0x6E = 110
00000040 14 00 | .. | - something (2) - message id?
00000040 64 31 3a 65 69 30 | d1:ei0| - bencoded dictionary (108)
00000050 65 31 3a 6d 64 31 31 3a 75 74 5f 6d 65 74 61 64 |e1:md11:ut_metad| { 'e': 0,
00000060 61 74 61 69 32 65 36 3a 75 74 5f 70 65 78 69 31 |atai2e6:ut_pexi1| 'metadata_size': 1702,
00000070 65 65 31 33 3a 6d 65 74 61 64 61 74 61 5f 73 69 |ee13:metadata_si| 'm': {'ut_metadata': 2, 'ut_pex': 1},
00000080 7a 65 69 31 37 30 32 65 31 3a 70 69 35 30 30 39 |zei1702e1:pi5009| 'reqq': 2048,
00000090 34 65 34 3a 72 65 71 71 69 32 30 34 38 65 31 3a |4e4:reqqi2048e1:| 'p': 50094,
000000a0 76 31 37 3a 6c 69 62 54 6f 72 72 65 6e 74 20 30 |v17:libTorrent 0| 'v': 'libTorrent 0.12.9' }
000000b0 2e 31 32 2e 39 65 |.12.9e |
000000b0 00 00 00 0c 05 | .....| - something (5) - checksum?

awk part of bash script not working properly

Everything seems fine when using script as #/bin/sh on ubuntu but now on using the same script with #/bin/bash on red hat this part is creating problem.
awk '{
for (i = NF - p - 2; i < NF - 2; i++)
printf "%s", ($i (i < NF - 2 - 1 ? OFS : ORS))
}' p="$_padlen" RS= ORS='\n' decrypt.txt > pad.txt
also this one ..
awk '{
for (i = NF - l - p - 2; i < NF - p - 2; i++)
printf "%s", ($i (i < NF - p - 2 - 1 ? OFS : ORS))
}' l="$_length" p="$_padlen" RS= ORS='\n' decrypt.txt > prot_n_data.txt
assuming $padlen=1 and $length=13 these are the respective outputs...
[root#localhost scripts]# cat decrypt.txt
00 15 00 15 00 0d dc ff 61 62 63 64 0a 00 01 11
Among last three bytes which are 00 01 11. the 00 is padding and 01 is padding length.
[root#localhost scripts]# cat pad.txt
0a
[root#localhost scripts]# cat prot_n_data.txt
00 15 00 15 00 0d dc ff 61 62 63 64 0a 00 01 11 00 15 00 15 00 0d dc ff
61 62 63 64
While the desired output is ...
# cat pad.txt
00
# cat prot_n_data.txt
00 15 00 15 00 0d dc ff 61 62 63 64 0a
Completely stucked getting no clue ...Please help me .
OR Atleast suggest me some alternative ...
EDIT:*
This is another sample file where the suggested solution not working out assuming $_padlen=3 and $_length=1159.
[root#localhost scripts]# cat decrypt.txt
00 17 00 17 04 87 5d c5 74 68 69 73 20 69 73 20
73 61 6d 70 6c 65 20 64 61 74 61 20 74 6f 20 73
65 6e 64 0a 77 65 20 73 68 6f 75 6c 64 20 63 6f
6e 63 65 6e 74 72 61 74 65 20 6f 6e 20 69 74 2e
0a 74 68 69 73 20 69 73 20 73 61 6d 70 6c 65 20
64 61 74 61 20 74 6f 20 73 65 6e 64 0a 77 65 20
73 68 6f 75 6c 64 20 63 6f 6e 63 65 6e 74 72 61
74 65 20 6f 6e 20 69 74 2e 0a 74 68 69 73 20 69
73 20 73 61 6d 70 6c 65 20 64 61 74 61 20 74 6f
20 73 65 6e 64 0a 77 65 20 73 68 6f 75 6c 64 20
63 6f 6e 63 65 6e 74 72 61 74 65 20 6f 6e 20 69
74 2e 0a 74 68 69 73 20 69 73 20 73 61 6d 70 6c
65 20 64 61 74 61 20 74 6f 20 73 65 6e 64 0a 77
65 20 73 68 6f 75 6c 64 20 63 6f 6e 63 65 6e 74
72 61 74 65 20 6f 6e 20 69 74 2e 0a 74 68 69 73
20 69 73 20 73 61 6d 70 6c 65 20 64 61 74 61 20
74 6f 20 73 65 6e 64 0a 77 65 20 73 68 6f 75 6c
64 20 63 6f 6e 63 65 6e 74 72 61 74 65 20 6f 6e
20 69 74 2e 0a 74 68 69 73 20 69 73 20 73 61 6d
70 6c 65 20 64 61 74 61 20 74 6f 20 73 65 6e 64
0a 77 65 20 73 68 6f 75 6c 64 20 63 6f 6e 63 65
6e 74 72 61 74 65 20 6f 6e 20 69 74 2e 0a 74 68
69 73 20 69 73 20 73 61 6d 70 6c 65 20 64 61 74
61 20 74 6f 20 73 65 6e 64 0a 77 65 20 73 68 6f
75 6c 64 20 63 6f 6e 63 65 6e 74 72 61 74 65 20
6f 6e 20 69 74 2e 0a 74 68 69 73 20 69 73 20 73
61 6d 70 6c 65 20 64 61 74 61 20 74 6f 20 73 65
6e 64 0a 77 65 20 73 68 6f 75 6c 64 20 63 6f 6e
63 65 6e 74 72 61 74 65 20 6f 6e 20 69 74 2e 0a
74 68 69 73 20 69 73 20 73 61 6d 70 6c 65 20 64
61 74 61 20 74 6f 20 73 65 6e 64 0a 77 65 20 73
68 6f 75 6c 64 20 63 6f 6e 63 65 6e 74 72 61 74
65 20 6f 6e 20 69 74 2e 0a 74 68 69 73 20 69 73
20 73 61 6d 70 6c 65 20 64 61 74 61 20 74 6f 20
73 65 6e 64 0a 77 65 20 73 68 6f 75 6c 64 20 63
6f 6e 63 65 6e 74 72 61 74 65 20 6f 6e 20 69 74
2e 0a 74 68 69 73 20 69 73 20 73 61 6d 70 6c 65
20 64 61 74 61 20 74 6f 20 73 65 6e 64 0a 77 65
20 73 68 6f 75 6c 64 20 63 6f 6e 63 65 6e 74 72
61 74 65 20 6f 6e 20 69 74 2e 0a 74 68 69 73 20
69 73 20 73 61 6d 70 6c 65 20 64 61 74 61 20 74
6f 20 73 65 6e 64 0a 77 65 20 73 68 6f 75 6c 64
20 63 6f 6e 63 65 6e 74 72 61 74 65 20 6f 6e 20
69 74 2e 0a 74 68 69 73 20 69 73 20 73 61 6d 70
6c 65 20 64 61 74 61 20 74 6f 20 73 65 6e 64 0a
77 65 20 73 68 6f 75 6c 64 20 63 6f 6e 63 65 6e
74 72 61 74 65 20 6f 6e 20 69 74 2e 0a 74 68 69
73 20 69 73 20 73 61 6d 70 6c 65 20 64 61 74 61
20 74 6f 20 73 65 6e 64 0a 77 65 20 73 68 6f 75
6c 64 20 63 6f 6e 63 65 6e 74 72 61 74 65 20 6f
6e 20 69 74 2e 0a 74 68 69 73 20 69 73 20 73 61
6d 70 6c 65 20 64 61 74 61 20 74 6f 20 73 65 6e
64 0a 77 65 20 73 68 6f 75 6c 64 20 63 6f 6e 63
65 6e 74 72 61 74 65 20 6f 6e 20 69 74 2e 0a 74
68 69 73 20 69 73 20 73 61 6d 70 6c 65 20 64 61
74 61 20 74 6f 20 73 65 6e 64 0a 77 65 20 73 68
6f 75 6c 64 20 63 6f 6e 63 65 6e 74 72 61 74 65
20 6f 6e 20 69 74 2e 0a 74 68 69 73 20 69 73 20
73 61 6d 70 6c 65 20 64 61 74 61 20 74 6f 20 73
65 6e 64 0a 77 65 20 73 68 6f 75 6c 64 20 63 6f
6e 63 65 6e 74 72 61 74 65 20 6f 6e 20 69 74 2e
0a 74 68 69 73 20 69 73 20 73 61 6d 70 6c 65 20
64 61 74 61 20 74 6f 20 73 65 6e 64 0a 77 65 20
73 68 6f 75 6c 64 20 63 6f 6e 63 65 6e 74 72 61
74 65 20 6f 6e 20 69 74 2e 0a 74 68 69 73 20 69
73 20 73 61 6d 70 6c 65 20 64 61 74 61 20 74 6f
20 73 65 6e 64 0a 77 65 20 73 68 6f 75 6c 64 20
63 6f 6e 63 65 6e 74 72 61 74 65 20 6f 6e 20 69
74 2e 0a 74 68 69 73 20 69 73 20 73 61 6d 70 6c
65 20 64 61 74 61 20 74 6f 20 73 65 6e 64 0a 77
65 20 73 68 6f 75 6c 64 20 63 6f 6e 63 65 6e 74
72 61 74 65 20 6f 6e 20 69 74 2e 0a 0a 0a 0a 0a
0a 0a 0a 0a 0a 0a 0a 00 00 00 03 11
The command I used is ..
[root#localhost scripts]# awk '{printf $0}' decrypt.txt | awk 'NF{for (i=NF-l-p-1;
i<NF-p-1;i++) printf $i" "; print ""}' p=3 l=1159
awk: (FILENAME=- FNR=1) fatal: attempt to access field -71
l is simply calculated as wc -w decrypt.txt|cut -d " " -f1 minus p minus 2
Try this (you might have to test it against few more samples)
[jaypal~/Temp]$ cat file.txt
00 15 00 15 00 0d dc ff 61 62 63 64 0a 00 01 11
For Pad.txt:
[jaypal~/Temp]$ awk 'NF{for (i=NF-p-1;i<NF-1;i++) printf $i; print ""}' p=1 file.txt
00
For Prot_n_data.txt:
[jaypal~/Temp]$ awk 'NF{for (i=NF-l-p-1;i<NF-p-1;i++) printf $i" "; print ""}' p=1 l=13 file.txt
00 15 00 15 00 0d dc ff 61 62 63 64 0a
UPDATED:
Since your feed file overlaps into a new line, NF needs to be handled differently. NF is number of fields on a particular record (which by default is a line).
pad.txt
awk 'BEGIN{RS=""} {for (i=NF-p-1;i<NF-1;i++) printf $i" "; print ""}' p=1 file.txt | sed 's/..\{47\}/&\n/g'
prot_n_data.txt
awk 'BEGIN{RS=""} {for (i=NF-l-p-1;i<NF-p-1;i++) printf $i" "; print ""}' p=3 l=1159 file1.txt | sed 's/..\{47\}/&\n/g'

Resources