Scripts to list all individual characters in a text file

eg.

For a file input.txtthat has the following content:

He likes cats, really?

the output will look like this:

H
e

l
i
k
s
c
a
t
,
r
l
y
?

Note that the order of characters in the output does not matter.

+5
source share
4 answers

What about:

echo "He likes cats, really?" | fold -w1 | sort -u
+10
source

One way to use is to grep -o .put each character in a new line and sort -uto remove duplicates:

$ grep -o . file | sort -u 

Or a solution that does not require sort -uor several commands written exclusively in awk:

$ awk '{for(i=1;i<=NF;i++)if(!a[$i]++)print $i}' FS="" file
+4
source

sed :

sed 's/./\0\n/g' input.txt | sort -u
0

awk:

awk  '{$1=$1}1' FS="" OFS="\n" file | sort -u
0

All Articles