Last Updated: February 25, 2016
·
673
· samhalicke

Interview Question - Name 1-10 ways to print the contents of a file.

I was asked this question:

"So how would you rate your linux chops on a scale of 1 to 10?"

"10."

"Show me 10 ways to print the contents of a text file."

$ echo 'foo' > testfile

cat testfile
tac testfile
less testfile
awk '{print;}' testfile
sed -n p testfile
tail -n`wc -l testfile` testfile
emacs testfile
<testfile        # requires use of zsh
dd if=testfile of=/dev/stdout
egrep '.*' testfile
while read line;do echo $line;done < testfile        # requires bash

I should also mention that you should never say 10. You will choke on your own hubris!

3 Responses
Add your response

Wow, I hope they gave you that job.

over 1 year ago ·

Heh. There's a reason I added the 'choke on your own hubris' part. ;-)

over 1 year ago ·

Also its worth saying that cat < testfile also reads the file but while opening it with bash and piping through cat rather than cat opening directly.

over 1 year ago ·