UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old October 24th, 2003, 01:38 PM
izzyfox izzyfox is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 1 izzyfox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
awk/sed solution

I need a solution to the following:

I have a file with hostnames listed i.e.

hostname1
hsotname2
hostname3

I also have another file that will contain one of the above hostnames in the file on any given line.

The problem is using breaking the awk statement to read the second file for a search match.

For example:

cd $systemPath
ls | awk -F. '{ print $1 }' \
> /tmp/hostList

Gives me a file listing of hostnames

Now I need to search for each hostname
in a different file, until I find the line containing one of the hostnames. There will be only one, but it will be amongst other fields, probably can use 'split' to create an array and get the hostname.

This won't work, but maybe you can see what I'm trying to do.

awk ' /$hostname/ { \
hostname = split($0, hostLine, " ")
for (i = 1; i <= z; ++i) {
print i, hostLine[i]
}
}' otherFile > hostFile(contains match)


Thanks

Reply With Quote
  #2  
Old October 25th, 2003, 06:50 AM
druuna druuna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 137 druuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 37 sec
Reputation Power: 0
Hi,

Your subject header asks for a sed/awk sollution, so my way of solving this might not be what you want........

You could do something like:
Code:
#!/bin/bash

HOST_NAME_FILE="/path/to/hostnames_file"

for THIS_HOST in `cat ${HOST_NAME_FILE}`
do
  echo "${THIS_HOST}: $(grep -h ${THIS_HOST} * )"
done


This code will produce lines that look like:

hostname1: word word hostname1 word word
hostname2: word hostname2 word word

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > awk/sed solution


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway