Unix command to select first few characters and last character of a line

I have a huge file and I want to select first 10 charcters and last 2 characters of everyline and than will filter the unique line.

I know, it must be easy bt I am new to unix scripting:)

Ex.
I have file as below and need to e3kbaird and last 2 characters. and than unique records.

e3kbaird 20120402104958362 1
e3kbaird 20120402104958362 1
e3kbaird 20120402104958362 1
e3kbaird 20120402104958362 1
e3kbaird 20120402104958362 1
e3kbaird 20120402104958362 1
e3kbaird 20120402104958362 1
 
awk '{print $1,$NF}' test.txt | sort -u
1 Like

If you're using modern bash or ksh, try this:

To strip first 10 chars:

$ x='e3kbaird 20120402104958362 1'
$ echo "${x:0:10}"
e3kbaird 2
$

To strip the last 2 characters:

$ echo "${x: -2}"
 1
$
1 Like

Thanks ! It worked.