Sponsored Content
Top Forums UNIX for Dummies Questions & Answers perl pack and unpack commands Post 302257387 by max_payne1234 on Wednesday 12th of November 2008 03:43:21 AM
Old 11-12-2008
perl pack and unpack commands

I have a file that contains user id and corresponding password.
Lets say password is "help". The below command will create a hex value for string "help".
perl -e 'print unpack "H*","help"'

So now password is in encoded format.

Then I decoded it in the script where am fetching the password.

perl -e 'print pack "H*","77636462614e3031"'


Now you help is required. In the second step when I am passing the hardcoded value, then it is able to decode it.
But when I am using a variable it is not working.

ex: var="77636462614e3031"
perl -e 'print pack "H*",$var'

This doesn't work. Let me know the syntax so that it will return correct value when I use it in a variable?
I am trying to execute this perl commands in LINUX OS.

Please help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl + pack() + spaceing question

ok guys and gals at the moment i am perplexed (prolly cuz i been looking at it to long) but here it is. OS: sol8 perlver: 5.8.0 shell: ksh answer must be in perl!! issue: when i use pack() it packs the data at the front of the requested field space. normally it wouldnt be a problem if... (1 Reply)
Discussion started by: Optimus_P
1 Replies

2. UNIX for Dummies Questions & Answers

does any body know how to unpack this file?????

this file i'm trying to unpack is a cloop file (1 Reply)
Discussion started by: amicrawler2000
1 Replies

3. Shell Programming and Scripting

Perl help!! (pack()?)

Hello everyone. I wrote a perl script to get the two answers from a value: x. By this, I want to do sqrt($x) in different precision. #!/usr/bin/perl print "Input the initial value x:\n"; chomp($x=<STDIN>); $comp=sqrt($x); $float_value=pack("f", $comp); $double_value=pack("d", $comp);... (2 Replies)
Discussion started by: Euler04
2 Replies

4. UNIX for Dummies Questions & Answers

simple unpack script

hi all.... I'm a newbie to Shell scripting and am trying to make a simple script that can unpack a variety of .tgz , .zip, .tar or .tar.gz archives to the a current directory i want the script to create a folder equivalent to the base name of the archive and then move the archive to a... (18 Replies)
Discussion started by: jboss
18 Replies

5. Shell Programming and Scripting

[PERL] Running unix commands within Perl Scripts

I understand that in order to run basic unix commands I would normally type at the prompt, I would have to use the following format system(ls -l); or exec(ls -l); But when I actually try to use the command, the script fails to compile and keeps telling me there is an error with this line. ... (1 Reply)
Discussion started by: userix
1 Replies

6. Shell Programming and Scripting

Bash equivalent of perl's pack function ?

Is there an equivalent of perl's pack function in bash ? Or in other words, how can I achieve the same thing in bash ? Much appreciated. (1 Reply)
Discussion started by: NewDeb
1 Replies

7. UNIX for Advanced & Expert Users

Perl-to-Oracle performance: DBI-pack visa 'sqlplus' usage

I wondering if anybody tried already or know about the performance to process some Oracle staff from Perl. I see it could be done by the DBI pachage (so, I guess, it is interface to the OCI, but who know how sufficiant it is..,) with all gemicks around (define, open, parce, bind,.. ), or it can... (8 Replies)
Discussion started by: alex_5161
8 Replies

8. UNIX for Dummies Questions & Answers

perl pack and unpack commands

I am using pack/unpack to encyrpt a file. syntax is below #!/bin/sh encrypt=`perl -e 'print unpack "H*","yourpassword"'` - echo $encrypt >/file/to/store/encrypted/password pass=`cat /file/to/store/encrypted/password` decrypt=`perl -e 'print pack "H*",$pass'` ... (2 Replies)
Discussion started by: erinlomo
2 Replies

9. Shell Programming and Scripting

Pack and unpack localtime in perl script

Hi I have a code like this: sub WriteEbcdicHeader { my $Htimestamp=localtime();#i need to pack and unpack this my $eheaderline = $Htimestamp; #packing has to be done here #unpacking has to be done after packing print $EOUTFILE return $eheaderline; } sub WriteEbcdicTrailer { ... (5 Replies)
Discussion started by: rbathena
5 Replies

10. Shell Programming and Scripting

what is the difference between commands compress, pack and gzip

Are the above commands does the same job ? same functionaliy ? If so, why do we have three utilities for the same functinality. (1 Reply)
Discussion started by: frintocf
1 Replies
pack(1) 						      General Commands Manual							   pack(1)

NAME
pack, pcat, unpack - Compresses and expands files SYNOPSIS
pack [-f] [-] file[.z]... unpack file[.z]... pcat file[.z]... STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: pack: XCU5.0 pcat: XCU5.0 unpack: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
Displays statistics about the input files. The statistics are calculated from a Huffman minimum redundancy code tree built on a byte-by- byte basis. Repeating the - (dash) on the command line toggles this function. Forces compaction of input files. Note These options are applicable to the pack command only. OPERANDS
A pathname of a file to be compressed or uncompressed. If the suffix is included on the pack command, pack searches for files without that suffix. If the suffix is not included, the files created have the original name with appended. If the suffix is included on a pcat or unpack command, the command processes files with that name. If the suffix is not included, the command appends to the file name. Files created by the unpack command will not have the suffix. DESCRIPTION
The pack command The pack command stores the specified file in a compressed form. The input file is replaced by a packed file with a name derived from the original file name (file.z), with the ownership, modes, access time and modification time of the original file preserved, if the invoking process has appropriate privileges. Directories cannot be compressed. If pack cannot create a smaller file, it stops processing and reports that it is unable to save space, unless you specify the -f option. (The -f option forces packing to occur even if the files cannot benefit from packing.) A failure to save space generally happens with small files or files with uniform character distribution. The amount of space saved depends on the size of the input file and the character frequency distribution. Because a decoding tree forms the first part of each file, you will generally not be able to save space with files smaller than three blocks. Typically, text files are reduced 25 to 40 percent. Object files, which use a larger character set and have a more uniform distribution of characters, show only a 10 percent reduction when packed. The exit value of the pack command is the number of files that it could not pack. Packing is not done under any one of the following con- ditions: The file is already packed. The file has links. The file is a directory. The file cannot be opened. No storage blocks are saved by packing. This is overridden by the -f option. A file called file.z already exists. The file cannot be created. An I/O error occurs during processing. The file is empty. The pcat command The pcat command reads the specified files, unpacks them, and writes them to standard output. The exit value of pcat is the number of files it was unable to unpack. A file cannot be unpacked if any one of the following occurs: The file cannot be opened. The file is not a packed file. [Tru64 UNIX] The file name (exclusive of the has more than 12 bytes and it resides on a System V file system. The unpack command The unpack command expands files created by pack. For each file specified, unpack searches for a file called file.z. If this file is a packed file, unpack replaces it by its expanded version. The unpack command names the new file name by removing the suffix from file. The new file has the same access modes, access and modification dates, and owner as the original packed file. The exit value is the number of files the unpack command was unable to unpack. A file cannot be unpacked if any one of the following occurs: The file cannot be opened. The file is not a packed file. A file with the unpacked file name already exists. The unpacked file cannot be created. NOTES
The pack, pcat and unpack utilities are marked LEGACY in XCU Issue 5. Both pcat and unpack operate only on files ending in you specify a file name that does not end in pcat and unpack add the suffix and search the directory for a file name with that suffix. [Tru64 UNIX] The unpack command writes a warning to standard output if the file it is unpacking has links. The new unpacked file has a different inode than the packed file from which it was created. However, any other files linked to the packed file's original inode still exist and are still packed. [Tru64 UNIX] If pack is used on files residing on a System V file system, the file names must contain no more than 12 bytes to allow space for the added extension. [Tru64 UNIX] If you try to use pack on a very small file, you might receive the following message: pack filename: No saving -- file unchanged The pack, pcat, and unpack commands are marked to be withdrawn from the XPG4-UNIX standard. The compress, uncompress, and zcat commands should be used instead. EXIT STATUS
The following exit values are returned: The pack command Successful completion. [Tru64 UNIX] The number of files that could not be packed. The pcat command Successful completion. [Tru64 UNIX] The number of files that could not be unpacked. The unpack command Successful completion. [Tru64 UNIX] The number of files that could not be unpacked. EXAMPLES
To compress files, enter: pack chap1 chap2 This compresses the files chap1 and chap2, replacing them with files named chap1.z and chap2.z. The pack command displays the per- cent decrease in size for each file. To display statistics about the amount of compression done, enter: pack - chap1 - chap2 This compresses the files chap1 and chap2 and displays statistics about chap1, but not about chap2. The first - (dash) turns on the statistic display, and the second turns it off. To display compressed files, enter: pcat chap1.z chap2 | more This displays the compressed files chap1.z and chap2.z on the screen in expanded form, a page at a time (more). The pcat command added the to the end of chap2, even though it was not entered. To use a compressed file without expanding the copy stored on disk, enter: pcat chap1.z | grep 'Greece' This pipes the contents of chap1.z in its expanded form to the grep command. To unpack packed files, enter: unpack chap1.z chap2 This expands the packed files chap1.z and chap2.z, replacing them with files named chap1 and chap2. You can give unpack file names either with or without the suffix. ENVIRONMENT VARIABLES
The following environment variables affect the execution of pack, pcat, and unpack: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the inter- nationalization variables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non- empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments). Determines the locale for the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. SEE ALSO
Commands: cat(1), compress(1), uncompress(1), zcat(1) Standards: standards(5) pack(1)
All times are GMT -4. The time now is 08:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy