jumping from one line to another


 
Thread Tools Search this Thread
Operating Systems Solaris jumping from one line to another
# 1  
Old 11-12-2010
Java jumping from one line to another

Hi,



Thanks

Last edited by rocky1954; 11-17-2010 at 11:00 PM.. Reason: due to some reasons
# 2  
Old 11-12-2010
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
Code:
awk -F"=" '{print $7}' sample.txt|awk -F")" '{print $1}'|sort -n|uniq -c|awk '{print $2}'


Hope this helps
Vj

Last edited by Franklin52; 11-14-2010 at 10:49 AM.. Reason: Please use code tags
# 3  
Old 11-12-2010
Thanks for your reply

Last edited by rocky1954; 11-18-2010 at 02:15 PM..
# 4  
Old 11-12-2010
Assuming multiple lines, that might not all have host data, and making it a bit simpler:

Code:
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.

Last edited by agama; 11-12-2010 at 07:47 PM.. Reason: clarification
# 5  
Old 11-12-2010
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

Code:
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.
# 6  
Old 11-12-2010
Code:
awk -F"[()=]" '{print$16}' infile | sort | uniq

# 7  
Old 11-12-2010
Thanks

Last edited by rocky1954; 11-18-2010 at 02:16 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Bash script jumping too quickly to the next command - crash

Hi, (I am not too good in command-lines). I am running a bash script and at some point my loop starts to run super quickly. Then, the steps after do not get processed and there is no further outpout generated. I tried with the sleep 20s option, as I thought some steps would get overlapped, but... (22 Replies)
Discussion started by: tremblayemilie9
22 Replies

3. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

4. BSD

Jumping from Solaris to BSD?

Hi all, I currently run an OpenSolaris (b134) server at home for share media between a few computers (all Macs at the moment). I use ZFS to mirror a couple of disks and have a couple of SMF manifests. My background is as a user of OS X and as a user of (Open)Solaris with formal training in... (7 Replies)
Discussion started by: forquare
7 Replies

5. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

6. Programming

Jumping to a particular line in a file

Hi, I have an output file which has more than 1,000,000,000 lines. I am accessing this file in another C++ program. Now while accessing the output file using cin, I want to jump, say, to the 5,000,000th line directly and start accessing data from there. Is this possible? Could someone please... (4 Replies)
Discussion started by: mugga
4 Replies

7. Shell Programming and Scripting

work area directory jumping script?

hi all, Ive been trying to find some way of doing this for ages but i have is a shell script that activates a python search and there it no tab completion. more familliar with tcsh at the moment but i'm a newbe. i was trying to make an easy way to browse to a list of working directories. ... (0 Replies)
Discussion started by: jvan
0 Replies

8. Shell Programming and Scripting

script to loop and check jumping seq.

Hi, Normally, I will manually to use "ll" command to list the following file from \FILE\CACHE\ directory and check the jump seq. Can I write a script to loop or/and check jump seq file (if jumped seq and show "missing seq no" message for me) -rw-rw----+ 1 user develop 14012 Sep 4... (1 Reply)
Discussion started by: happyv
1 Replies

9. Programming

jumping to a specific line in a text file

hi everybody! i need to read a specific line from a text file using C. can any one suggest how to do it. i m aware abt fread(), fwrite(), fseek()... but using these allows the pointer to be moved 1 character at a time. Is there a way i could jump directly to a line if i know the line number?... (4 Replies)
Discussion started by: mridula
4 Replies

10. Shell Programming and Scripting

Jumping to next line with awk

I am defining an awk function (Solaris v8 ksh) of: function firstletter { echo "$line" | awk '{get=substr($1,1,1);print get}' | read FL } I am starting a wile loop with a: for line in `cat inputfile.lst` When I call the function from within the for loop it works great fine. From within... (4 Replies)
Discussion started by: gozer13
4 Replies
Login or Register to Ask a Question