?
Solved

grep

Posted on 2001-07-10
2
Medium Priority
?
376 Views
Last Modified: 2012-06-27
I am using grep to get print options from the same line the name of a printer is found on in a file.  In some files the name of the printer may appear two or more times.  I need to get the option from the line the the name of the printer on the first occurance only.

Is there a way to modify the below line so it will only get one occurance of the printer option?

printtype=`grep -i ${printname} /usr/local/etc/hbspool.conf | cut -f3 -d" "`

Or is there another way to operate on the $printtype variable after its value is set and get the string up to the first whitespace?

Thanks for your help.
0
Comment
Question by:mzehner
2 Comments
 

Accepted Solution

by:
earthman1968 earned 400 total points
ID: 6269771
If the line you want is always the first one then pipe the output of the grep through the head command Eg:-

printtype=`grep -i {printname} /usr/local/etc/hbspool.conf | cut -f3 -d" " | head -1`
0
 

Expert Comment

by:SpideyMod
ID: 8275941
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question