Character generation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Character generation
# 1  
Old 02-20-2012
Character generation

I need a (bash) script to echo to the screen all possible 4 character hex combinations of: A-F, 0-9. I beleive there are 65,535 approx combos. Output something like this:

0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
...
...
FFFE
FFFF
# 2  
Old 02-20-2012
Dirty Smilie
Code:
#!/bin/sh
for a in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
 for b in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
  for c in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
   for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
    echo $a$b$c$d
   done
  done
 done
done

# 3  
Old 02-20-2012
Code:
for ((i=1; i<=65535; i++)); do 
  printf "%04X\n" "$i"
done

Posix:
Code:
i=0
while [ $i -le 65534 ] ; do 
  printf "%04X\n" "$((i+=1))"
done


Last edited by Scrutinizer; 02-20-2012 at 02:48 PM..
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 4  
Old 02-20-2012
Code:
for i in {1..65535}
do
   echo "obase=16;ibase=10;$i" | bc
done

# 5  
Old 02-20-2012
@anchal, when using bc this would be more efficient, no?
Code:
{ echo obase=16;ibase=10
  for i in {1..65535}; do
    echo $i
  done
} | bc

This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 02-20-2012
Code:
"$((i+=1))"

Thanks for this, Scrutinizer, I was searching for something like this for a long time now Smilie
# 7  
Old 02-21-2012
Quote:
Originally Posted by Scrutinizer
@anchal, when using bc this would be more efficient, no?
Code:
{ echo obase=16;ibase=10
  for i in {1..65535}; do
    echo $i
  done
} | bc

Definitely yes Smilie
Thanks for pointing out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies

2. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

3. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

4. Shell Programming and Scripting

File character adjustment based on specific character

i have a reqirement to adjust the data in a file based on a perticular character the sample data is as below 483PDEAN CORRIGAN 52304037528955WAGES 50000 89BP ABCD MASTER352 5434604223735428 4200 58BP SOUTHERN WA848 ... (1 Reply)
Discussion started by: pema.yozer
1 Replies

5. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

6. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

7. UNIX for Advanced & Expert Users

if 4th and 5th character of sting -ge 45 then add 1 to 3rd character

I want to know how to, given a string like W87151WR71C, if the 4th and 5th character (in this case 15) are greater than 45, then to add 1 to the 3rd character (in this case 7) and assign the revised string the variable name MODSTRING. Thanks in advance. This is ultimately to grab info from... (6 Replies)
Discussion started by: glev2005
6 Replies

8. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

9. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

10. UNIX for Dummies Questions & Answers

read a variable character by character, substitute characters with something else

im having trouble doing this: i have a variable with 2 characters repeating e.g. aababbbaaaababaabbaabbba is there a way i can search the variable for a's and b's and then change a's to b's and b's to a's? im guessing its like getting the 1's compliment of the string im doing this in... (2 Replies)
Discussion started by: vipervenom25
2 Replies
Login or Register to Ask a Question