Shell Programming Blog Shell Programming Blog

Monday 24 September 2012

look command to print lines in Linux

Unknown | 10:32 |


 


Let me introduce a simple UNIX/Linux command which is very useful but not that popular. The name of the command is 'look'. As the name suggests, this command displays lines beginning with a given string.


Usage:
look string <file>

The look utility displays any lines in 'file' which contain 'string' as a prefix. This can be a simple alternative of using

$ grep "^string" <file>

If file is not specified while using the look command, the file /usr/share/dict/words will be used, only alphanumeric characters are compared and by default the case of alphabetic characters is ignored.

This utility can be very useful to look up the dictionary words from 'usr/share/dict/words'

e.g.
$ look Das
Dasheen
Dashers
Dashier
Dashiki
Dashing
Dashpot
Dassies
Dastard
Dasyure



In order to ignore the case of alphabetic characters you can use its -f option. (similar to grep -i)

Exit Status:
The exit status of the look utility will be 0 if one or more lines found and displayed.
The exit status of the look utility will be 1 if no lines found
The exit status will be >1 if there is an error.

1 comment:

Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.

Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
3. Please do not spam, spam comments will be deleted immediately upon my review.

Regards,
Mohamed Abubakar Sittik A

 

Shell Programming Copyright © 2012 Shell Programming theme is Designed by Abusittik, Shell Programming