When starting a new thread in the Shell Programming and Scripting forum, please always tell us what operating system and shell you're using.
Also tell us what you have tried to solve this on your own.
Did you search for similar threads that may have already explained how to do what you're trying to do? There seem to be several threads in the list of topics you might find helpful at the end of output for this thread that exactly address what you want to do.
This is for bash shell.
Yes, I tried below:
cat test.txt |awk '{print substr($1, 1, length-1)}'
test.txt:
SCDE1
SF9
STR1D2
SREDF21
FRED
STER2R4
Output:
SCDE
SF
STR1D
SREDF2
FRE
STER2R
This will allow me to remove whatever last character in the line, but the requirement is only remove if numeric (1-9).
Appreciate if any suggestion given.
You still haven't told us what operating system you're using.
Note that numeric is 0 through 9; not 1 through 9.
Note that awk and sed are perfectly capable of reading a file by itself without creating a pipe and an unneeded process ( cat ) to slow down processing and waste system resources.
One might try any of the following (all of which are very similar to suggestions in the threads listed at the bottom of this page) each of which should do what you requested: