Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6858279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:08:16+00:00 2026-05-27T02:08:16+00:00

Everything seems fine when using script as #/bin/sh on ubuntu but now on using

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:08:17+00:00Added an answer on May 27, 2026 at 2:08 am

    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'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a socket program and everything seems fine when compiling. First I
I'm running fabric (Django deployment to apache) and everything seems to work fine until
I'm trying to re-install a DLL in the GAC, everything seems to work fine
When I try to start Firefox using Process.Start and ProcessStartInfo (.NET) everything seems to
Well is there? From everything I've read, it seems like the answer is no,but
I'm using Elmah to log exceptions for my website, everything seems to be all
I'm using the jCarousel Lite jQuery plugin on a page, but it seems to
I am using Server Side processing of DataTables . Everything seems to be working
I cannot send the notification to iphone. Everything seems fine, as the service works
I am trying to get a grid displayed using jqGrid. Everything seems to work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.