Monday, February 25, 2013

Unix Questions

1) How to Print/Display first line of a file?

>> head -1 file.txt

head -1 prints first line in the file specified.

Or you can use 'sed' command.

$> sed '2,$ d' filename.txt'

Sed command deletes all the lines starting from 2nd line to end of line [Represented by '$']. Though sed command does not modify file content. It only prints first line.