Sponsored Content
Top Forums Shell Programming and Scripting Still trying to get a grep -c that works Post 302188039 by popeye on Tuesday 22nd of April 2008 01:57:02 PM
Old 04-22-2008
Still trying to get a grep -c that works

I am trying to get a count of each line

sub runit2 {
my ($file1a, $file2a) = @_;
my $file1_vala = $file1a->get;
my $file2_vala = $file2a->get;
open (FILE1a, "$file1_vala") or die;
open (FILE2a, "$file2_vala") or die;
chomp(my @strings = <FILE2a>);
while (1) {
foreach $pattern (<FILE1a>) {
chomp($pattern);
last if $pattern =~ /^\s*$/;
my @matches = eval {
grep $pattern eq $_, @strings;
};
if ($@) {
print "Error: $@";
} else {
my $count = @matches;
print "$count $pattern \n",
#$text->insert('end', "$count $pattern $_\n");
}
}
return;
}





1 ip routing
1 ip classless
1 no ip bootp server
1 no ip http server
1 no ip http secure-server
1 ip bgp-community new-format
1 no access-list 23
1 no access-list 51
1 logging buffered 4096 debugging
1 banner motd ^
6 *************************************************
6**************************************************
2 ^
1 banner exec ^
6**************************************************
2 * LEGAL NOTICE *
6 ***************************************************
6 ***************************************************
2 * LEGAL NOTICE *
6 ****************************************************
2 ^
1 ip dhcp excluded-address 10.8.26.1 10.8.26.100
1 ip dhcp excluded-address 10.8.26.200 10.8.26.254
1 no auto-summary
1 snmp-server view BLOCK iso included
1 snmp-server view BLOCK ipAddrEntry.*.*.*.*.* included
1 snmp-server view BLOCK ipAddrEntry.*.10.*.*.* excluded
1 snmp-server view BLOCK ipNetToMediaEntry.*.*.*.*.*.* included
1 snmp-server view BLOCK ipNetToMediaEntry.*.*.10.*.*.* excluded
1 snmp-server view BLOCK atEntry.*.*.*.*.*.*.* included
1 snmp-server view BLOCK atEntry.*.*.*.10.*.*.* excluded
2 snmp-server ifindex persist
2 snmp-server enable traps snmp authentication linkdown linkup coldstart warmstart
1 snmp-server enable traps frame-relay
1 snmp-server enable traps frame-relay subif
1 snmp-server enable traps config
1 ip tacacs source-interface loopback0
1 snmp-server trap-source loopback0
1 ip flow-export source fa0/0
1 ip flow-export version 5 origin-as
1 ip flow-export destination 10.15.1.2 9996
1 ip flow-cache timeout active 1
1 ip flow-cache timeout inactive 15
2 snmp-server ifindex persist
1 logging trap notifications
1 logging source-interface fa0/0
2 snmp-server enable traps snmp authentication linkdown linkup coldstart warmstart
1 privilege exec level 1 traceroute
1 privilege exec level 1 ping
1 privilege exec level 1 show configuration
1 line con 0
2 exec-timeout 5 0
3 login
1 line aux 0
2 exec-timeout 5 0
3 login
1 line vty 0 4
1 exec-timeout 30 0
1 no privilege level 15
1 no access-class 23 in
3 login
1 end


The easiest thing to look at is the 3 login lines. login appears in file 2 3 times. I only want a single output of "3 login" and not that statement every time the script encounters login.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How the for loop works?

Hi, I have a landing area where some files keep on coming after irregular intervals of time. From this landing area, I need to move files to another directory for processing. For this, I am using a for loop to find certain kinds of files in the landing area. Now my question is, suppose I start... (6 Replies)
Discussion started by: neelaksh
6 Replies

2. UNIX for Dummies Questions & Answers

How ls | wc -l works?

ls displays files in tabbed output. Say a directory contains 3 files. ls will list all 3 in one line. So, I expect ls | wc -l to give 1, but it counts the nr of files and gives 3. Can someone explain how this works? (3 Replies)
Discussion started by: krishmaths
3 Replies

3. Programming

how this works?

pls explain me how this works.... DECODE (SUBSTR (field, 1, 1),'''', '''''' || field || '''','''' || field || '''') here field is a column in an oracle table.... (7 Replies)
Discussion started by: vijay_0209
7 Replies

4. UNIX for Dummies Questions & Answers

>./a.pl works, >a.pl - does not

When I try to execute script, I get message: >aa.pl zsh: command not found: aa.pl but >./aa.pl works OK. What to change in environment to force the former way to work? Thank you, Alex Z (4 Replies)
Discussion started by: zzol
4 Replies

5. Shell Programming and Scripting

how it works ? sftp

Hi, I am curious about this script , how it is running ..? #!/bin/sh echo "OK, starting now..." ftp remotehost <<EOF When I run , it is asking OK, starting now... Password:Name (remotehost): SHould I enter only password ? and explain me how it works.. thanks in advance.. (3 Replies)
Discussion started by: hegdeshashi
3 Replies

6. UNIX for Advanced & Expert Users

How this works?

I have a program............ #include<stdio.h> #include<unistd.h> main() { if(fork == 0) { printf("Hi every body:p!!!!!!!!!!"); } } This program works with out any error. here fork is not a system call. It just act as a variable.But how it works without declaring it? What data type it... (19 Replies)
Discussion started by: carolsanjeevi
19 Replies

7. UNIX for Dummies Questions & Answers

Need a visual grep tool that works on windows via sftp

Hi, Could you please suggest a tool that connects like WINSCP/Putty and allows me to search a remote Unix directory for a certain text pattern (grep) ? Regards, Bhanja. (1 Reply)
Discussion started by: bhanja_trinanja
1 Replies

8. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

9. Shell Programming and Scripting

Grep works on Linux but fails on Solaris

Hi, On linux i have the below command working fine. grep -o '<name>.*</name>' deploy.tmp | sed 's/\(<name>\|<\/name>\)//g' deploy.tmp But the same is failing on Solaris uname -a SunOS mymac 5.10 Generic_150400-23 sun4v sparc sun4v Can you tell me how can i get it work on Solaris ?... (6 Replies)
Discussion started by: mohtashims
6 Replies

10. Shell Programming and Scripting

Grep -q not works with multiples grep in same line

Hi, I'm trying to make a grep to see if exists occurrences with a sentence like these: grep -qi "message" file0 | grep -i $date | grep -vi "exception" echo $? 1 If I execute without -q modifier I can find occurrences. Someone could help me please? Thanks and sorry for my English! (1 Reply)
Discussion started by: mierdatuti
1 Replies
snmp-ups(8)						      Network UPS Tools (NUT)						       snmp-ups(8)

NAME
snmp-ups - Driver for RFC 1628 SNMP UPS equipment NOTE
This man page only documents the hardware-specific features of the snmp-ups driver. For information about the core driver, see nutups- drv(8). SUPPORTED HARDWARE
Any UPS that is RFC 1628 (UPS MIB) compliant. EXPERIMENTAL DRIVER
This driver has been tagged experimental and is not built by default. REQUIREMENTS
This driver needs UCD SNMP, aka Net-SNMP installed to compile successfully. See http://www.net-snmp.org/ for more information. On Red Hat 7.2, these packages are required: ucd-snmp-devel-4.2.3-1, ucd-snmp-4.2.3-1, ucd-snmp-utils-4.2.3-1 You must install SNMP-UPS-MIB.txt in your MIBs directory - typically /usr/share/snmp/mibs/, but it may vary from system to system. You can generate this from chapter 4 of RFC 1628 (see http://www.faqs.org). EXTRA ARGUMENTS
This driver supports the following optional settings in the ups.conf(5): community=name Set community name (default = public) snmp_version=version Set SNMP version (default = v1, the other allowed value is v2c) INSTALLATION
This driver is not built by default. You can build it by using "configure --with-drivers=snmp-ups" before calling make. IMPLEMENTATION
The hostname of the UPS is specified with the "port" value in ups.conf, i.e.: [snmp] driver = snmp-ups port = snmp-ups.example.com community = public snmp_version = v1 SUPPORTED VARIABLES
INFO_MFR UPS Manufacturer INFO_MODEL UPS Model INFO_FIRMREV Firmware/Software Version INFO_STATUS OFF, OL, OB, BOOST, TRIM INFO_BATTPCT Battery percentage INFO_RUNTIME Predicted runtime on battery INFO_BATTVOLT Battery Voltage INFO_OUTVOLT Output Voltage PLANNED SUPPORT
INFO_UTILITY Input Voltage INFO_ACFREQ AC Frequency INFO_UPSTEM UPS Temperature INFO_LOADPCT Load Percentage CMD_? Not determined AUTHORS
Arnaud Quette, Hans Ekkehard Plesser SEE ALSO
The core driver: nutupsdrv(8) Internet resources: The NUT (Network UPS Tools) home page: http://www.exploits.org/nut/ NUT mailing list archives and information: http://lists.exploits.org/ Tue Oct 22 2002 snmp-ups(8)
All times are GMT -4. The time now is 03:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy