Sponsored Content
Full Discussion: uniq -c in the pipeline
Top Forums Shell Programming and Scripting uniq -c in the pipeline Post 302643535 by fletch00 on Saturday 19th of May 2012 08:48:59 PM
Old 05-19-2012
uniq -c in the pipeline

Hello gurus - I must be missing something, or there is a better way - pls enlighten me

I'm on a Solaris 10 vm running the following pipeline to reduce some apache logs (actually lynx dumps of /server-status/ when threads are above a threshold) to a set of offending DDoS IP addresses.

Code:
awk '{print $NF}' * | egrep '\.' | egrep -i -v HTTP | egrep -v '/' | uniq -c | sort -nr | more


From the uniq manpage -

Code:
     -c              Precedes each output line with  a  count  of
                     the number of times the line occurred in the
                     input.

So why am I getting duplicate lines in the uniq output?

Code:
  19 127.0.0.1
  14 127.0.0.1
  11 127.0.0.1
   7 120.168.0.166
   6 127.0.0.1
   5 65.52.109.73
   3 65.52.109.73
   3 65.52.109.73
   3 65.52.109.73
   3 65.52.109.73
   3 65.52.109.73
   3 65.52.109.73
   3 65.52.109.73
   3 65.52.109.73
   3 65.52.109.73


thanks

Last edited by Scrutinizer; 05-20-2012 at 01:02 AM.. Reason: code tags
 

9 More Discussions You Might Find Interesting

1. Programming

C program help please! input from pipeline

I have a project where I have to use bzcat to uncompress a file and use that output as the data to run another program on. I understand that you would do (bzcat filename.bz2 ! program name) but then how do you access that data in the c program??? Please help thanks (2 Replies)
Discussion started by: kinggizmo
2 Replies

2. UNIX for Dummies Questions & Answers

Unix Pipeline help

Does anyone know how to answer this? I have tried many different commands, I just cant get it right..... Search the file 'data' for all of the lines that contain the pattern 'unx122' and put those lines in the file 'matches'. (2 Replies)
Discussion started by: netmaster
2 Replies

3. Shell Programming and Scripting

Comments within a shell pipeline

I've got a very ugly pipeline for analyzing web server logs (but nevermind the application; I've come across this in other scripts as well). I want to nicely comment the steps in the pipeline, but I can't seem to do it. I know, for instance that in csh/sh/bash, a # begins a comment, and any... (2 Replies)
Discussion started by: otheus
2 Replies

4. Shell Programming and Scripting

Retaining Pipeline values

Hi, I am trying to calculate a few values using the below code but it dosent seem to be working. for i in 1 2 3 4 5 6 7 8 do j=`expr $i + 3` x =`head -$j temp1|tail -1|cut -f24 -d","` y =`head -$j temp1|tail -1|cut -f25 -d","` c =`expr $x / $y` echo "$c" >> cal_1 done I am not... (4 Replies)
Discussion started by: sachinnayyar
4 Replies

5. Shell Programming and Scripting

Shell pipeline help for a n00b

I need to read input from a file, and make sure nothing prints after column 72. basically, ignore input after character 72 until the next newline character. Any help is appreciated. I have been searching forever! (10 Replies)
Discussion started by: Gbear
10 Replies

6. Shell Programming and Scripting

Change the delimiter from Comma to Pipeline

Hello All, I need to convert a csv file to pipeline delimiter file in UNIX. The data in file itself contains comma with double qouted qualifier apart from the comma separator. Let me know how to do it. Appreciate any help if awk can be used to do it. Mentioned below is the sample record of... (14 Replies)
Discussion started by: Arun Mishra
14 Replies

7. Shell Programming and Scripting

If statement with pipeline

Hi Can anybody please explain me the following script in detail Value=`echo "if ( ${FACTOR} >= 1 ) {1}" | bc` What does "{1}" mean to here ? (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

8. Shell Programming and Scripting

Command pipeline trouble

Hello, I am attempting to ssh to a server and run a set of commands on a remote set of servers. I am getting the following error below, I am thinking quotes may be the problem. This command works on the local machine in bash. Not when I ssh to a remote server. Basically the command should... (3 Replies)
Discussion started by: jaysunn
3 Replies

9. Shell Programming and Scripting

Using cat and pipeline to execute script

hi this is a homework assignment i need some help with it mostly works. script file #!/usr/bin/env bash #create dictionary file grep -E '.{3}' /usr/share/dict/british-english > db.txt #create remove_word to test file touch removeW.txt #palindrome function palin() { ... (1 Reply)
Discussion started by: crepe6
1 Replies
UNIQ(1) 						    BSD General Commands Manual 						   UNIQ(1)

NAME
uniq -- report or filter out repeated lines in a file SYNOPSIS
uniq [-c | -d | -u] [-i] [-f num] [-s chars] [input_file [output_file]] DESCRIPTION
The uniq utility reads the specified input_file comparing adjacent lines, and writes a copy of each unique input line to the output_file. If input_file is a single dash ('-') or absent, the standard input is read. If output_file is absent, standard output is used for output. The second and succeeding copies of identical adjacent input lines are not written. Repeated lines in the input will not be detected if they are not adjacent, so it may be necessary to sort the files first. The following options are available: -c Precede each output line with the count of the number of times the line occurred in the input, followed by a single space. -d Only output lines that are repeated in the input. -f num Ignore the first num fields in each input line when doing comparisons. A field is a string of non-blank characters separated from adjacent fields by blanks. Field numbers are one based, i.e. the first field is field one. -s chars Ignore the first chars characters in each input line when doing comparisons. If specified in conjunction with the -f option, the first chars characters after the first num fields will be ignored. Character numbers are one based, i.e. the first character is character one. -u Only output lines that are not repeated in the input. -i Case insensitive comparison of lines. DIAGNOSTICS
The uniq utility exits 0 on success, and >0 if an error occurs. COMPATIBILITY
The historic +number and -number options have been deprecated but are still supported in this implementation. SEE ALSO
sort(1) STANDARDS
The uniq utility is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible. HISTORY
A uniq command appeared in Version 3 AT&T UNIX. BSD
June 6, 1993 BSD
All times are GMT -4. The time now is 05:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy