Skip to main content
Incorrect `wc -c` edited
Source Link
user232326
user232326

If you count the characters without hex:

$ sed 's/\([^\]*\)\\x[0-9A-Fa-f][0-9A-Fa-f]/\1/g' dummy_hex.txt | LC_ALL=C wc -c
14

And substract that from the whole file count:

$ <dummy_hex.txt wc -c dummy_hex.txt
30

You could get the count of hex characters (times 4). In one script:

#!/bin/bash
a=$(sed 's/\([^\]*\)\\x[0-9A-Fa-f][0-9A-Fa-f]/\1/g' dummy_hex.txt | wc -c)
b=$(<dummy_hex.txt wc -c dummy_hex.txt)
count=$(( (b-a)/4 ))
echo "$count"

Prints:

$ ./script
4

Remember that wc counts bytes (not locale dependent characters).

If you count the characters without hex:

$ sed 's/\([^\]*\)\\x[0-9A-Fa-f][0-9A-Fa-f]/\1/g' dummy_hex.txt | LC_ALL=C wc -c
14

And substract that from the whole file count:

$ wc -c dummy_hex.txt
30

You could get the count of hex characters (times 4). In one script:

#!/bin/bash
a=$(sed 's/\([^\]*\)\\x[0-9A-Fa-f][0-9A-Fa-f]/\1/g' dummy_hex.txt | wc -c)
b=$(wc -c dummy_hex.txt)
count=$(( (b-a)/4 ))
echo "$count"

Prints:

$ ./script
4

Remember that wc counts bytes (not locale dependent characters).

If you count the characters without hex:

$ sed 's/\([^\]*\)\\x[0-9A-Fa-f][0-9A-Fa-f]/\1/g' dummy_hex.txt | LC_ALL=C wc -c
14

And substract that from the whole file count:

$ <dummy_hex.txt wc -c
30

You could get the count of hex characters (times 4). In one script:

#!/bin/bash
a=$(sed 's/\([^\]*\)\\x[0-9A-Fa-f][0-9A-Fa-f]/\1/g' dummy_hex.txt | wc -c)
b=$(<dummy_hex.txt wc -c )
count=$(( (b-a)/4 ))
echo "$count"

Prints:

$ ./script
4

Remember that wc counts bytes (not locale dependent characters).

Source Link
user232326
user232326

If you count the characters without hex:

$ sed 's/\([^\]*\)\\x[0-9A-Fa-f][0-9A-Fa-f]/\1/g' dummy_hex.txt | LC_ALL=C wc -c
14

And substract that from the whole file count:

$ wc -c dummy_hex.txt
30

You could get the count of hex characters (times 4). In one script:

#!/bin/bash
a=$(sed 's/\([^\]*\)\\x[0-9A-Fa-f][0-9A-Fa-f]/\1/g' dummy_hex.txt | wc -c)
b=$(wc -c dummy_hex.txt)
count=$(( (b-a)/4 ))
echo "$count"

Prints:

$ ./script
4

Remember that wc counts bytes (not locale dependent characters).