jumping from one line to another

Hi,

Thanks

Hi Rocky1954,
Are you looking to find a unique list of hostnames from the file?
if so use the below code.
Assume the file containing that output is called sample.txt

awk -F"=" '{print $7}' sample.txt|awk -F")" '{print $1}'|sort -n|uniq -c|awk '{print $2}'

Hope this helps
Vj

Thanks for your reply

Assuming multiple lines, that might not all have host data, and making it a bit simpler:

awk '
        /HOST=/ {                # for each input line with host name
                sub( "^.*HOST=<", "" );  # delete everything up to host name
                sub( ">.*", "" );        #delete everything past hostname
                print;
        }
' <input-file | sort -u

If you need the hostname contained within < and > in the output, remove those characters from the substitution pattern.

mvijayv's example was basically doing the same thing, but using more processes than necessary. First awk set the field separator to = and printed the 7th field ($). Second awk set the field separater to close paren and printed the first field. Then the output was passed through sort and unique to sort the list and remove duplicates.

This will work if the host is proceeded by "HOST=" on each line, it only uses 1 awk process.
It also supports multiple HOST= on 1 line

awk -F"[=,(,)]" '
{
  for (i=1;i<=NF;i++) {
    if ($i == "HOST") H[$(i+1)]++;
  }
}
END { for(host in H) print host; }' logfile

It uses awk with "=" "(" and ")" as delimiters and uses the field following HOST as as has array index. After the whole file is read in the contents of the hash array is printed.

awk -F"[()=]" '{print$16}' infile | sort | uniq

Thanks

awk -F"[=() ]" '
{
  if(NR==1) cur=$1
  if (cur != $1)
  {
      for(host in H) print cur,host,H[host];
      delete H;
      cur=$1;
  }
  for (i=1;i<=NF;i++) if ($i == "HOST") H[$(i+1)]++;
}
END { for(host in H) print cur,host,H[host] }' logfile
awk -F'[(=)]' '{for(i=0;++i<=NF;){if($i=="HOST"){_[$1 OFS $(i+1)]++}}}END{for(i in _)print i,_}' file
sed 's|(.*HOST=\([^)]*\).*|\1|' input
[ctsgnb@shell ~]$ echo '24-APR-2009 (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=<service_name>)(CID=(PROGRAM=root)(HOST=<host_name>)(U SER=rock)))' | sed 's|(.*HOST=\([^)]*\).*|\1|'
24-APR-2009 <host_name>
[ctsgnb@shell ~]$

danmero, could put ' ' in -F list to avoid double space in output, result is not in date order - might need to sorting it after.
ctsgnb, no count, if more that 1 "HOST=" on line only first is output.