Sponsored Content
Top Forums Shell Programming and Scripting Help with egrep or grep command to meet multiple criteria Post 302398922 by MinBee on Friday 26th of February 2010 12:28:47 AM
Old 02-26-2010
Thanks rdcwayx, anbu23, and vivekraj for your response.

The output is very large, but I will trim it down to 6 records in the file.

I attempted to use anbu23 code, but it kept returning with 0 count.

Code:
sed -n "/robot type:.*TLD/{N;/barcode:.*AA/s/\n//p;}" testing.txt | wc -l

I hope I can make this one more clear.

There are 6 records in the testing.txt file. For each record, I would like a count if it fits the criteria with barcode of AA* and robot type of TLD*.

Based on the 6 records, I should get a total count of 4 that fits the barcode of AA* and robot type of TLD*.

barcode AA0379, AA0400, AA0500, AA0700 all fit the criteria.

Thanks in advance.

Filename: testing.txt

Code:
================================================================================
media ID:              AA0379
media type:            1/2" cartridge tape 3 (24)
barcode:               AA0379
media description:     ---
volume pool:           ScratchPool (7)
robot type:            TLD - Tape Library DLT (8)
================================================================================
media ID:              BB0234
media type:            1/2" cartridge tape 3 (24)
barcode:               BB0234
media description:     ---
volume pool:           ScratchPool (7)
robot type:            NONE - Not Robotic (0)
================================================================================
media ID:              AA0400
media type:            1/2" cartridge tape 3 (24)
barcode:               AA0400
media description:     ---
volume pool:           ScratchPool (7)
robot type:            TLD - Tape Library DLT (8)
================================================================================
media ID:              AA0500
media type:            1/2" cartridge tape 3 (24)
barcode:               AA0500
media description:     ---
volume pool:           ScratchPool (7)
robot type:            TLD - Tape Library DLT (8)
================================================================================
media ID:              AA0600
media type:            1/2" cartridge tape 3 (24)
barcode:               AA0600
media description:     ---
volume pool:           ScratchPool (7)
robot type:            NONE - Not Robotic (0)
================================================================================
media ID:              AA0700
media type:            1/2" cartridge tape 3 (24)
barcode:               AA0700
media description:     ---
volume pool:           ScratchPool (7)
robot type:            TLD - Tape Library DLT (8)

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching for multiple criteria in log files?

I would like a simple shell script that will allow me to display to screen all unsuccessful su attempts in my sulog file, for the present date. I have been trying several different combinations of commands, but I can't quite get the syntax correct. The mess I have right now (don't laugh) is... (4 Replies)
Discussion started by: Relykk
4 Replies

2. UNIX for Dummies Questions & Answers

How to use the "grep/egrep" command to search files.

Hi Team, I am new to this forum and also trying to learn Unix. I will highly appriciate your help if you can help me to get the right command . {{{ I use the command " today | egrep '(10:| 11: )' | grep ERROR " to grep all the files that has been error betweeen 10 to 11... (6 Replies)
Discussion started by: rkhanal
6 Replies

3. UNIX for Dummies Questions & Answers

Difference between grep, egrep & grep -i

Hi All, Please i need to know the difference between grep, egrep & grep -i when used to serach through a file. My platform is SunOS 5.9 & i'm using the korn shell. Regards, - divroro12 - (2 Replies)
Discussion started by: divroro12
2 Replies

4. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

5. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

6. Shell Programming and Scripting

Globbling with multiple criteria (UNIX Shell)

I am new to UNIX Shell. I want to list the files names in the current directory that are not start with 'AB' and have at least two characters. For example, say I have those files in the current directory: AB, AC, AD, AE, B, C. After executing the command, AC, AD, AE will be listed on the screen. ... (6 Replies)
Discussion started by: Ray Sun
6 Replies

7. Shell Programming and Scripting

Finding the right file with multiple sort criteria

Hello, I have files in a directory with names like, ./f0/84.40_E1200_85.39_E1300_f0_r00_1300-ON-0.25_S7A_v4_47.19.1.out.txt ./f0/84.40_E1200_85.83_E1200_f0_r00_1200-ON-0.25_S7A_v4_47.19.1.out.txt ./f0/84.60_E1100_86.45_E1100_f0_r00_1100-ON-0.25_S7A_v4_47.19.1.out.txt... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

8. Shell Programming and Scripting

Multiple Grep command

Hi, I have an url.txt I need check them and grep some data. url.txt domain.com domain2.com domain3.com .....All sites urls have in source this patterns: "web=pattern1" "net++pattern2" "office**pattern3" I need this output: domain.com: pattern1,pattern2,pattern3 domain2.com:... (3 Replies)
Discussion started by: tara123
3 Replies

9. Shell Programming and Scripting

Only print specific xml values that meet two criteria in python

I have a large XML file that I want to parse, and only print one specific value if two values are met. This is the code so far: #!/usr/local/bin/python import xml.etree.ElementTree as ET tree = ET.parse('onedb-dhcp.xml') root = tree.getroot() # This successfully gets all... (1 Reply)
Discussion started by: brianjb
1 Replies

10. UNIX for Beginners Questions & Answers

Insert content from file 1 to file 2 in specific criteria meet

Hi , I'm looking for some code that can copy and paste form file1 to file2 with 2 criterial meet. file1: test "sp-j1" test "sp-j2" test "sp-j3" test "sp-j4" file2: sub Pre_Shorts1 (Status_Code, Message$) global Status !if Message$ <> "" then print... (3 Replies)
Discussion started by: kttan
3 Replies
ZGREP(1)						    BSD General Commands Manual 						  ZGREP(1)

NAME
zgrep, zegrep, zfgrep -- print lines matching a pattern in gzip-compressed files SYNOPSIS
zgrep [grep-flags] [--] pattern [files ...] zegrep [grep-flags] [--] pattern [file ...] zfgrep [grep-flags] [--] pattern [file ...] DESCRIPTION
zgrep runs grep(1) on files or stdin, if no files argument is given, after decompressing them with zcat(1). The grep-flags and pattern arguments are passed on to grep(1). If an -e flag is found in the grep-flags, zgrep will not look for a pattern argument. zegrep calls egrep(1), while zfgrep calls fgrep(1). EXIT STATUS
In case of missing arguments or missing pattern, 1 will be returned, otherwise 0. SEE ALSO
egrep(1), fgrep(1), grep(1), gzip(1), zcat(1) AUTHORS
Thomas Klausner <wiz@NetBSD.org> BSD
December 28, 2003 BSD
All times are GMT -4. The time now is 02:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy