unique entries needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unique entries needed
# 1  
Old 06-04-2011
unique entries needed

Hi All,

I have the following command which returns the output like this -

PHP Code:
wget URL|grep hostname|awk '{print $1,$3}'|/usr/bin/perl -nle 'm{"(.*?)".*?//(.*):(\d+)/} and print "$1 $2 $3"'|while read host port
do
echo 
check_env_$port
echo host
done 
OUTPUT
Appname hostname port
Appname2 hostname port2 ...

Appnames are all unique , while hostname is not since I am grepping for single hostname(vip).
Some of the ports are not unique so I am getting the same port for 4-5 different appnames.

Within the same snippet of code I want to add a number to echo command so the its unique..
e.g. check_env_1_1234
check_env_2_1234

So for port 1234 it should increment the numbers.

If that's too hard then atleast get unique entries so that I don't get check_env_1234 not more than once which ever comes first and ignore the rest of the entries with the same port.

Thanks,
Jack.
# 2  
Old 06-04-2011
I wonder how this works at all. It looks like host will be assigned the value of $1, while port will be assigned "$2 $3".
Code:
... and print "$1 $2 $3"'|while read host port

But in any case, you could create a variable per port number, say n1234 for port 1234, and use it to store the count like this:
Code:
test -z "$(eval echo \$n$port)" && n${port}=1 || ((n${port}++))

Then you could print out your command like this:
Code:
eval echo check_env_\$n${port}_$port

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unique entries in multiple files

Hello, I have a directory with a log files(many of them). Lines look like this: Sep 1 00:05:05 server9 pop3d-ssl: LOGIN, user=abc@example.com, ip=, port= Sep 1 00:05:05 server9 pop3d-ssl: LOGOUT, user=abc@example.com, ip=, port=, top=0, retr=0, rcvd=12, sent=46, time=0 Sep 1 00:05:05... (19 Replies)
Discussion started by: ramirez987
19 Replies

2. Shell Programming and Scripting

Unique entries based on a range of numbers.

Hi, I have a matrix like this: Algorithm predicted_gene start_point end_point A x 65 85 B x 70 80 C x 75 85 D x 10 20 B y 125 130 C y 120 140 D y 200 210 Here there are four tab-separated columns. The first column is the used algorithm for prediction, and there are 4 of them A-D.... (8 Replies)
Discussion started by: flyfisherman
8 Replies

3. UNIX for Dummies Questions & Answers

Sorting and saving values based on unique entries

Hi all, I wanted to save the values of a file that contains unique entries based on a specific column (column 4). my sample file looks like the following: input file: 200006-07file.txt 145 35 10 3 147 35 12 4 146 36 11 3 145 34 12 5 143 31 15 4 146 30 14 5 desired output files:... (5 Replies)
Discussion started by: ida1215
5 Replies

4. UNIX for Dummies Questions & Answers

Print unique lines without sort or unique

I would like to print unique lines without sort or unique. Unfortunately the server I am working on does not have sort or unique. I have not been able to contact the administrator of the server to ask him to add it for several weeks. (7 Replies)
Discussion started by: cokedude
7 Replies

5. Shell Programming and Scripting

Deriving unique entries from multiple repeating patterns

Dear All, I have a below one column data.(example) Col1 1 2 . . 25 8 9 25 1 2 . . 25 Where each entry(row) is a number from 1-25, but in place whereever mentioned with . we have all the entries 1-25, but some places where ever no . like in 8 9 25 I have only 3 entries. No I... (14 Replies)
Discussion started by: ks_reddy
14 Replies

6. Shell Programming and Scripting

Change unique file names into new unique filenames

I have 84 files with the following names splitseqs.1, spliseqs.2 etc. and I want to change the .number to a unique filename. E.g. change splitseqs.1 into splitseqs.7114_1#24 and change spliseqs.2 into splitseqs.7067_2#4 So all the current file names are unique, so are the new file names.... (1 Reply)
Discussion started by: avonm
1 Replies

7. Shell Programming and Scripting

unique entries

Hi, I have a file ENST12345 yes ENST11445 no ENST12345 yes ENST24689 no ENST24689 yes ENST34567 no what I want is for each unique identifier if atleast one of them has a value of "yes" then all of it entries need to be imported or else it should be skipped. o/p... (2 Replies)
Discussion started by: Diya123
2 Replies

8. Shell Programming and Scripting

Filtering a file for unique entries

Hi All, I am trying to filter out a txt file containing 2 columns. Which has got website name and response time as below. Website_name response_time yahoo 22 google 21 yahoo 34 rediff 45 google 43 rediff 31 I want filter the above file with unique website names which has got highest... (5 Replies)
Discussion started by: anilreddy103
5 Replies

9. Shell Programming and Scripting

Finding unique entries without sorting

Hi Guys, I have two files that I am using: File1 is as follows: wwe khfgv jfo jhgfd hoaha hao lkahe This is like a master file which has entries in the order which I want. (4 Replies)
Discussion started by: npatwardhan
4 Replies

10. Shell Programming and Scripting

get part of file with unique & non-unique string

I have an archive file that holds a batch of statements. I would like to be able to extract a certain statement based on the unique customer # (ie. 123456). The end for each statement is noted by "ENDSTM". I can find the line number for the beginning of the statement section with sed. ... (5 Replies)
Discussion started by: andrewsc
5 Replies
Login or Register to Ask a Question