SysTutorials

ASCII Table, Character Codes, and Linux Text Tools

· updated April 11, 2026

ASCII stands for American Standard Code for Information Interchange. It’s a 7-bit character encoding standard mapping numeric values (0-127) to printable characters and control codes. Since computers work with numbers at the lowest level, ASCII provides a universal way to represent text: each character has a unique numeric value.

Standardized in 1963, ASCII remains foundational to modern computing. Most character-encoding schemes today (UTF-8, UTF-16, ISO-8859-1) maintain backward compatibility with ASCII for the 0-127 range, meaning the first 128 characters are identical across these encodings.

ASCII Ranges

The 128 ASCII codes divide into three categories:

Converting Characters and ASCII Codes

Using printf

Convert a character to its ASCII code:

printf '%d\n' "'A"
# Output: 65

Convert an ASCII code to a character:

printf '\x41\n'
# Output: A

Or using octal:

printf "\\$(printf '%03o' 65)\n"
# Output: A

Multiple conversions at once:

printf 'Char: A\n'
printf '  Decimal: %d\n' "'A"
printf '  Hex: %x\n' "'A"
printf '  Octal: %o\n' "'A"
# Output:
# Char: A
#   Decimal: 65
#   Hex: 41
#   Octal: 101

Using od (octal dump)

Inspect ASCII values in a file or string:

echo "Hello" | od -An -td1
#  72  101  108  108  111

Display in hexadecimal:

echo "Hello" | od -An -tx1
#  48  65  6c  6c  6f

Display with character names:

echo "test" | od -c
# 0000000 t e s t \n

Using xxd for hex dumps

echo "test" | xxd
# 00000000: 7465 7374 0a                             test.

The 0a at the end is the newline character (LF, decimal 10).

Using Python

Convert individual characters:

ord('A')        # Returns: 65
chr(65)         # Returns: 'A'

Process entire strings:

[ord(c) for c in "Hello"]  # Returns: [72, 101, 108, 108, 111]
{ord(c): c for c in "ASCII"}  # Returns: {65: 'A', 83: 'S', 67: 'C', 73: 'I'}

Using Bash parameter expansion

Extract the ASCII value of the first character:

var="Hello"
printf '%d\n' "'${var:0:1}"
# Output: 72

Key Control Characters

Most control codes are obsolete for their original purposes, but a few remain relevant in system administration and text processing:

CodeDecimalHexNamePurpose
NUL00x00NullString terminator in C
BEL70x07BellAlert signal (rarely used)
BS80x08BackspaceCursor control
TAB90x09Horizontal TabText formatting, field separation
LF100x0ALine FeedNewline (Unix/Linux)
CR130x0DCarriage ReturnLegacy newline (Windows/old Mac)
ESC270x1BEscapeANSI escape sequences, terminal control
DEL1270x7FDeleteErase character

Complete ASCII Table (0-127)

DecOctHexCharDecOctHexCharDecOctHexCharDecOctHexChar
00000x00NUL320400x20SP641000x40@961400x60`
10010x01SOH330410x21!651010x41A971410x61a
20020x02STX340420x22“661020x42B981420x62b
30030x03ETX350430x23#671030x43C991430x63c
40040x04EOT360440x24$681040x44D1001440x64d
50050x05ENQ370450x25%691050x45E1011450x65e
60060x06ACK380460x26&701060x46F1021460x66f
70070x07BEL390470x27‘711070x47G1031470x67g
80100x08BS400500x28(721100x48H1041500x68h
90110x09TAB410510x29)731110x49I1051510x69i
100120x0ALF420520x2A*741120x4AJ1061520x6Aj
110130x0BVT430530x2B+751130x4BK1071530x6Bk
120140x0CFF440540x2C,761140x4CL1081540x6Cl
130150x0DCR450550x2D:771150x4DM1091550x6Dm
140160x0ESO460560x2E.781160x4EN1101560x6En
150170x0FSI470570x2F/791170x4FO1111570x6Fo
160200x10DLE480600x300801200x50P1121600x70p
170210x11DC1490610x311811210x51Q1131610x71q
180220x12DC2500620x322821220x52R1141620x72r
190230x13DC3510630x333831230x53S1151630x73s
200240x14DC4520640x344841240x54T1161640x74t
210250x15NAK530650x355851250x55U1171650x75u
220260x16SYN540660x366861260x56V1181660x76v
230270x17ETB550670x377871270x57W1191670x77w
240300x18CAN560700x388881300x58X1201700x78x
250310x19EM570710x399891310x59Y1211710x79y
260320x1ASUB580720x3A:901320x5AZ1221720x7Az
270330x1BESC590730x3B;911330x5B[1231730x7B{
280340x1CFS600740x3C<921340x5C\1241740x7C|
290350x1DGS610750x3D=931350x5D]1251750x7D}
300360x1ERS620760x3E>941360x5E^1261760x7E~
310370x1FUS630770x3F?951370x5F_1271770x7FDEL

Practical Use Cases

Finding Non-ASCII or Control Characters

Identify lines containing bytes outside the standard ASCII range:

grep -P -n "[\x80-\xFF]" filename

View control characters in context:

od -c filename | head -20

Check for embedded null bytes (often problematic in text files):

grep -c $'\x00' filename

Byte-Level File Analysis

Examine raw bytes with ASCII equivalents side-by-side:

xxd -g 1 filename | head -20

This format shows hex values and printable ASCII characters, making it straightforward to spot text embedded in binary data.

Add the -l flag to limit output by byte count:

xxd -g 1 -l 512 filename

Extracting Text from Binary Files

Extract all printable ASCII strings from a binary file:

strings filename

Filter by minimum string length:

strings -n 8 filename    # Only strings 8+ characters long

Combine with grep to find specific patterns:

strings binary_file | grep -i "version"

Text Processing and Line Endings

Check file line ending types:

file filename  # Shows line ending type (CRLF, LF, etc.)

Find lines with non-standard line endings (mixed LF/CR):

od -c filename | grep -E "(\\\\n|\\\\r)"

Convert DOS line endings (CR+LF) to Unix (LF):

dos2unix filename

Or using sed (works on systems without dos2unix):

sed -i 's/\r$//' filename

Convert Unix to DOS line endings:

sed -i 's/$/\r/' filename

Log Analysis

Check for control characters that might corrupt log parsing:

cat logfile | od -c | grep -E '\\[0-7][0-7][0-7]'

Display any character outside printable ASCII in escape notation:

cat logfile | sed 's/[^[:print:]\n]/./g'

Generate a summary of non-ASCII characters found:

od -An -tx1 logfile | tr -s ' ' '\n' | sort | uniq -c | grep -v '^[[:space:]]*[0-9]\+ 2[0-7]' | grep -v '^[[:space:]]*[0-9]\+ [0-4][0-9a-f]'

Working with Special Characters in Scripts

Safely handle strings containing ASCII codes:

# Store a tab character
tab=$'\t'
# Store a newline
newline=$'\n'
# Use in commands
awk -v tab="$tab" '{print $1 tab $2}' input.txt

Generate test data with specific ASCII codes:


# Create a file with null-terminated strings
printf 'string1\x00string
← All posts