Masterminder
Masterminder

Reputation: 1135

Print/Obtain first character of a line in a text file in UNIX

Was wondering how you print/obtain the first character in a text file in unix.

i.e say "9 textfile.txt" would return 9

thx

Upvotes: 1

Views: 8804

Answers (1)

kev
kev

Reputation: 161954

You can use head to get first char of file:

head -c 1 file.txt

If you want first char of every line:

grep -o ^. file.txt

Or

cut -c 1 file.txt

Upvotes: 8

Related Questions