|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > awk/sed solution |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|