[SOLVED] Pass search results to awk, and use awk output to search other files
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Pass search results to awk, and use awk output to search other files
I am trying to create a shell script that runs a search, passes the results to awk, then uses it's output to run another search and finally print the results. Note that I do not have access to use awk to do the original search (checkuser). I realize that the code below is embarassingly bad.. but I post it here, in hopes that it might clarify what I am trying to get at. Any assistance is greatly appreciated
Checkuser is a compiled program that touches systems I don't have permissions on. What I am extracting from it is an IP address. I want to take that address and search all files in a particular directory except for one, then print a line, each time the address is found. Sorry that the code is ugly.. I'm really new. It looks exactly as I typed it in, with one exception; I had a few more spaces in this bit:
Thank you for your time and effort. I'm posting from my phone, currently, so cannot immediately post full output of checkuser. Yes, I am searching for framedipaddress, as it is the first word on the line of checkuser output that contains the IP address. $2 is the second item on that line, and is the address. The $ after it is to indicate that a carriage return follows (so that when I grep for 10.0.0.5, I do not get a match from 10.0.0.50, etc).
The solution did not work. The search requirements and printed output have changed (only slightly), though what I need still fits the request in the subject of the thread. The below code works, but I need to tell it to only do the grep if the length of $cdslvar is greater than zero. If you can show me how to stop the grep on zero length $cdslvar, that would be great. If you can show me how to do checkuser, piped to a single awk that completes this goal, it would be even better.
I looked it over, and over, until I figured out a way to get exactly what I need. If anybody else is looking for a way to pass results from a search to awk, then use that awk's results to set a variable, then use awk to search files for the variable that was set .... here it is (though I'm positive there are more efficient ways to do this)
"cdslvar" is just the name that I picked for my own variable
"checkuser <user> dsl" is a program that we use
"framedipaddress" is a field in the results from checkuser
"/var/named/zones/acs.public/*.db" are the files that I am searching
Last edited by bspears1; 07-20-2012 at 04:25 PM.
Unfortunately with such a vague answer it will not really help me to help you. Was there no output? Wrong output? Wrong format?
As you have now also changed the arguments being passed into checkuser it is hard to gauge if the error is due to missing options.