Note that there are some explanatory texts on larger screens.

plurals
  1. POawk part of bash script not working properly
    text
    copied!<p>Everything seems fine when using script as <code>#/bin/sh</code> on ubuntu but now on using the same script with <code>#/bin/bash</code> on red hat this part is creating problem.</p> <pre><code> awk '{ for (i = NF - p - 2; i &lt; NF - 2; i++) printf "%s", ($i (i &lt; NF - 2 - 1 ? OFS : ORS)) }' p="$_padlen" RS= ORS='\n' decrypt.txt &gt; pad.txt </code></pre> <p>also this one ..</p> <pre><code> awk '{ for (i = NF - l - p - 2; i &lt; NF - p - 2; i++) printf "%s", ($i (i &lt; NF - p - 2 - 1 ? OFS : ORS)) }' l="$_length" p="$_padlen" RS= ORS='\n' decrypt.txt &gt; prot_n_data.txt </code></pre> <p>assuming <code>$padlen=1</code> and <code>$length=13</code> these are the respective outputs...</p> <pre><code>[root@localhost scripts]# cat decrypt.txt 00 15 00 15 00 0d dc ff 61 62 63 64 0a 00 01 11 </code></pre> <p>Among last three bytes which are <code>00 01 11</code>. the <code>00</code> is padding and <code>01</code> is padding length.</p> <pre><code>[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 </code></pre> <p><strong>While the desired output is ...</strong> </p> <pre><code># cat pad.txt 00 # cat prot_n_data.txt 00 15 00 15 00 0d dc ff 61 62 63 64 0a </code></pre> <p>Completely stucked getting no clue ...Please help me .</p> <p>OR Atleast suggest me some alternative ...</p> <p><em>EDIT:</em>*</p> <p>This is another sample file where the suggested solution not working out assuming <code>$_padlen=3</code> and <code>$_length=1159</code>.</p> <pre><code> [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 </code></pre> <p>The command I used is ..</p> <pre><code> [root@localhost scripts]# awk '{printf $0}' decrypt.txt | awk 'NF{for (i=NF-l-p-1; i&lt;NF-p-1;i++) printf $i" "; print ""}' p=3 l=1159 awk: (FILENAME=- FNR=1) fatal: attempt to access field -71 </code></pre> <p><code>l</code> is simply calculated as <code>wc -w decrypt.txt|cut -d " " -f1</code> minus <code>p</code> minus <code>2</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload