Solved Extract last 5 characters of each line

June 3, 2012 at 10:13:50
Specs: UNIX
Hallo zusammen,

ich habe eine 15.000 Zeilen Datei mit Zeilen unterschiedlicher Länge.
Ich benötige von jeder Zeile nur die letzten 5 Zeichen.
Hat einer eine einfache Idee dieses mit Standard Unix Kommandos zu erstellen?

Hi all,

I have a 15,000 line file with lines of different lengths.
I need of each line, only the last 5 characters.
Has a simple idea to create this standard Unix commands?

See More: Extract last 5 characters of each line

Report •

June 4, 2012 at 00:03:30
✔ Best Answer

# use awk to print the last 5 characters of each line
awk '
print substr($0,(length($0) - 4))
} ' datafile > newdatafile

Report •

June 10, 2012 at 12:13:38
Thanks for the good and fast help
It runs

Report •

August 7, 2012 at 07:11:21
Nails: Personally, I would have used a Korn shell script and used typeset to right justify the line into a variable that was the last 5 characters. You know how much of a stickler am for doing as much as possible in the shell without resorting to external utilities.


typeset -R5 Line
exec 3<input.file

while read -u3 Line
print $Line
done >> output.file

Report •
Related Solutions

Ask Question