Solved

grep

Posted on 2001-07-10
2
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
earthman1968 earned 100 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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