How do I extract data from nmblookup in bash shell script?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have actually used awk, sed, grep, head, tail, cut and many of those utilities before. But I haven't used some of them in a long time, and as you know, it's easy to forget things after a long while.
Okay, well if I use head to grab the first line, that gets me somewhere (I use head, but usually without parameters - I forgot it could do that). How would you suggest I yank PCNAME from that line?
I tried using cut, but I was left with white space on the left and right of the word. I tried using sed to nuke the white spaces that cut left behind, but it wasn't working. I thought maybe awk would be the way to go (instead of cut/sed), but I couldn't get it to do what I wanted either. I tried perl, but my perl skills are so rusty I couldn't remember how to get what I wanted in a one-liner. It's just been too long since I've dabbled with some of these utilities.
So assume I'm down to one line. What would be your suggestion in terms of yanking that PCNAME from that line? I need it in a BASH variable so I can print it later with some other info.
And again, thanks to everyone for the help! You're all awesome.
I have actually used awk, sed, grep, head, tail, cut and many of those utilities before. But I haven't used some of them in a long time, and as you know, it's easy to forget things after a long while.
Jup human brain is just not what it's suppose to be
I just wanted to scotch the upcoming battle of awk vs sed and whats best for what.
While you now have your script ready and good just a bit of hint. Just use man program name from time to time. It always provided me with some additional ideas how to solve things.
Oh, I've used man pages many times before. I'm not a Linux newbie. But most of what I've done the past few years is more systems administration, which hasn't included sed or awk. As I said, I've used perl quite a bit in the past too, but it's been quite a long time since then.
The man pages, in my opinion anyway, are often hit and miss. Sometimes they are extremely helpful, and in other cases, they're very little help. And in the case of sed vs awk (which have larger man pages), my schedule is so fragmented that I end up having to re-read sections because I can't remember what I read from my last 'session.'
In any event, the script does what it is meant to do, and all is good. I've added code that handles queries from nmblookup which don't produce results, and the script handles those IPs accordingly.
All in all, I do appreciate the assistance from all of you.
In any event, the script does what it is meant to do, and all is good. I've added code that handles queries from nmblookup which don't produce results, and the script handles those IPs accordingly.
What does it look like? I'm intrigued by all the talk of sed and awk when a pure bash solution was given here (and it worked after zhjim had fixed the typos)
The man pages, in my opinion anyway, are often hit and miss. Sometimes they are extremely helpful, and in other cases, they're very little help. And in the case of sed vs awk (which have larger man pages), my schedule is so fragmented that I end up having to re-read sections because I can't remember what I read from my last 'session.'
I am totaly with you in this point. sed and awk man pages are nearly good for nothing. But most man pages will give you a good idea what purpose they have and that most of the time in the first paragraph.
As it's always hard to predict what level of skill/knowledge a person has it did not wanted to insult you. Man pages are for me just like a quick talk to a co-worker about a problem. 2 minutes of talking/reading can save hours of work.
What does it look like? I'm intrigued by all the talk of sed and awk when a pure bash solution was given here (and it worked after zhjim had fixed the typos)
I guess there are just hosts that don't have a netbios name and so return an emtpy set.
And truly spoken I like your solution best cause it's pure bash and using only one external programm. This got array usage in bash on my list
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.