In this HackerRank Tail of a Text File #2 problem solution In this challenge, we practice using the tail command to display the last n characters of a text file.

Display the last 20 characters of an input file.

Input Format

A text file.

Output Format

Output the last 20 characters of the text file.

HackerRank Tail of a Text File #2 problem solution


Problem solution.

touch file
cat > file
tail -c 20 file


Second solution.

read lines
while read line; do
    lines=$lines$'\n'$line
done
echo "$lines" | tail -c 20


Third solution.

tail -c 20