Sponsored Content
Full Discussion: Decoding a string
Top Forums UNIX for Dummies Questions & Answers Decoding a string Post 302608997 by balajesuri on Monday 19th of March 2012 06:19:51 AM
Old 03-19-2012
Code:
#! /bin/bash

shopt -s extglob

x=$1
while [ ${#x} -gt 0 ]
do
    num=${x%%[a-zA-Z]*}; x=${x##+([0-9])}
    str=${x%%[0-9]*}; x=${x##+([a-zA-Z])}
    for ((i=1; i<=$num; i++))
    do
        echo -e "$str\c"
    done
done
echo

Code:
[root@host ~]# ./test.sh 10ab11cd12ef
ababababababababababcdcdcdcdcdcdcdcdcdcdcdefefefefefefefefefefefef
[root@host ~]# ./test.sh 3a4b5c
aaabbbbccccc
[root@host ~]# ./test.sh 10hello12world
hellohellohellohellohellohellohellohellohellohelloworldworldworldworldworldworldworldworldworldworldworldworld

Just out of curiosity, what is the real commercial scenario where you're requiring something like this?

Last edited by balajesuri; 03-19-2012 at 07:31 AM..
This User Gave Thanks to balajesuri For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

Decoding of Core Dump

Hi ALL, Is it possible to decode the core dumb file to find the error? I get an Memory Core Dumb error with an core file. Regards, P. Prathaban. (3 Replies)
Discussion started by: p_prathaban
3 Replies

2. Shell Programming and Scripting

decoding commands

hi please can anyone help me in decoding shell commands. i need a way to decode the encrypted shell commands. (8 Replies)
Discussion started by: rochitsharma
8 Replies

3. Solaris

problem when decoding a binary file

I tried to decode a binary script using the command 'uudecode'. but it is giving error as 'No begining line'. 'uudecode -o <outfile name> <binary file>' Please help me in resolving this. (4 Replies)
Discussion started by: vamshikrishnab
4 Replies

4. IP Networking

Packet decoding

Hi, wondering if anyone can suggest a tool to me that will let me either cut & paste hex or type it in for packet decoding. I want to be able to decode a packet as done with tcpdump or wireshark, but I want to be able to manually input the hex myself. (2 Replies)
Discussion started by: Breakology
2 Replies

5. UNIX for Dummies Questions & Answers

URL decoding with awk

The challenge: Decode URL's, i.e. convert %HEX to the corresponding special characters, using only UNIX base utilities, and without having to type out each special character. I have an anonymous C code snippet where the author assigns each hex digit a number from 0 to 16 and then does some... (2 Replies)
Discussion started by: uiop44
2 Replies

6. Shell Programming and Scripting

[Solved] Decoding a base 64 string

Is it possible to decode a base 64 string in linux or unix. If so, related commands or reference notes would be really helpful. (1 Reply)
Discussion started by: chandu123
1 Replies

7. Shell Programming and Scripting

FTP decoding

I am trying to understand a UNIX script which FTPs certain files from a remote location to the local machine. I understand the basic FTP command but the UNIX script uses the following command: ftp -n -i -v > $logftp_trg 2>&1 <<! open $MFX_FTP_SERVER user $MFX_FTP_LOGIN $MFX_FTP_PWD Can anyone... (5 Replies)
Discussion started by: Bhavesh Sharma
5 Replies

8. Shell Programming and Scripting

Decoding and pattern matching

Hello, I have a huge file with over 700,00 SNPs with 18 columns. One column is in the format --+-+ ---++ ????? -???? Now i have another list which corresponds to this code in a particular order A-1 B-7 C-11 D-3 E-100 Now I need to match the expression above to the pattern,... (1 Reply)
Discussion started by: nans
1 Replies

9. Programming

ASN1 decoding error

Hi, fellows i am modifying asn1 schema to be able to decode a file, but i am hitting a error on one of the fields using free online tool asn1-playground. I suspect i need to change type and have tried with IDENTIFIER but it doesn't help...any ideas check the schema and file down , please ... (0 Replies)
Discussion started by: tahchiev01
0 Replies

10. OS X (Apple)

Unicode encoding and decoding, OSX 10.13.5.

I am struggling here to understand...... The default encoding. See photo 1. Why does this NOT work? #!/bin/bash # Code for OSX 10.13.5. default UNICODE encoding. echo"" echo "The default UTF-8..." locale echo"" echo "Change to 8 bit ASCII only..." LANG="en_GB.US-ASCII" export... (2 Replies)
Discussion started by: wisecracker
2 Replies
DISKTAB(5)							File Formats Manual							DISKTAB(5)

NAME
disktab - disk description file SYNOPSIS
#include <disktab.h> DESCRIPTION
Disktab is a simple date base which describes disk geometries and disk partition characteristics. The format is patterned after the term- cap(5) terminal data base. Entries in disktab consist of a number of `:' separated fields. The first entry for each disk gives the names which are known for the disk, separated by `|' characters. The last name given should be a long name fully identifying the disk. The following list indicates the normal values stored for each disk entry. Name Type Description ns num Number of sectors per track nt num Number of tracks per cylinder nc num Total number of cylinders on the disk b0 str Filename of block zero primary bootstrap for device ba num Block size for partition `a' (bytes) bd num Block size for partition `d' (bytes) be num Block size for partition `e' (bytes) bf num Block size for partition `f' (bytes) bg num Block size for partition `g' (bytes) bh num Block size for partition `h' (bytes) fa num Fragment size for partition `a' (bytes) fd num Fragment size for partition `d' (bytes) fe num Fragment size for partition `e' (bytes) ff num Fragment size for partition `f' (bytes) fg num Fragment size for partition `g' (bytes) fh num Fragment size for partition `h' (bytes) pa num Size of partition `a' in sectors pb num Size of partition `b' in sectors pc num Size of partition `c' in sectors pd num Size of partition `d' in sectors pe num Size of partition `e' in sectors pf num Size of partition `f' in sectors pg num Size of partition `g' in sectors ph num Size of partition `h' in sectors se num Sector size in bytes (default 512) sf bool supports bad144-style bad sector forwarding so bool partition offsets in sectors ty str Type of disk (e.g. removable, winchester) Disktab entries may be automatically generated with the diskpart program. FILES
/etc/disktab SEE ALSO
newfs(8), diskpart(8), getdiskbyname(3) BUGS
This file shouldn't exist, the information should be stored on each disk pack. 4.2 Berkeley Distribution May 17, 1986 DISKTAB(5)
All times are GMT -4. The time now is 04:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy