Extract the first 2 letters in each line of a file using a single command Terminal

0

I want to extract the first 2 letters of each line from a file and save it in a variable and print it in a single command. Can anyone help me with the command? Considering my file has 20 - 30 lines and file name is extracter.txt.

Aravind S

Posted 2016-01-29T15:27:52.587

Reputation: 194

Answers

1

The simplest way to get the first 2 chars of each line is

cut -c 1-2 extracter.txt

Your question is not clear about what you want to save into a variable.

glenn jackman

Posted 2016-01-29T15:27:52.587

Reputation: 18 546

I just want to print it on screen. – Aravind S – 2016-01-29T15:58:16.197