I've got a file containing:
Georgia
Unix
Google
The desired output is:
Georg
Un
Goog
I've got a file containing:
Georgia
Unix
Google
The desired output is:
Georg
Un
Goog
The shell Parameter Expansion and using Substring removal ${parameter%word}/Substring Expansion ${parameter:offset:length} syntax.
"${line%??}" # strip the shortest suffix pattern match the word
"${line::-2}" # strip last 2 characters (`bash 4.2` and above)
"${line: : -2}" # in older you could add spaces between OR
"${line::${#line}-2}"
"${line: : -2}" wouldn't work in older versions either. ${line:0:${#line}-2} would and also work in ksh93 (where that ${var:offset:length} syntax comes from) and recent versions of zsh. See also $line[1,-3] in zsh.
– Stéphane Chazelas
Aug 17 '17 at 07:36