Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Searching a pattern in .gz files Post 302879403 by in2nix4life on Thursday 12th of December 2013 09:49:14 AM
Old 12-12-2013
Code:
#!/bin/bash
#
# -- given a search pattern search both text
# -- and compressed files and return matches

# check command-line for search value
if [ $# -ne 2 ]
then
    echo "[!] Usage: ${0##*/} <search pattern> <position>"
    exit 1
fi

# store search value
val=$1

# store position
pos=$2

# get current working directory and switch to it
cwd=$(pwd)
cd $cwd

# loop through both text and compressed files
# and search for the given value
shopt -s nullglob
for f in *
do
    if [[ $f =~ "gz" ]]
    then
        result=$(zcat $f | awk -F',' -v s=$val -v p=$pos '$p ~ s {print s}')
        if [ "$result" == "$val" ]
        then
            echo "[*] Found pattern [ $val ] in file [ $f ]."
        fi
    else
        result=$(awk -F',' -v s=$val -v p=$pos '$p ~ s {print s}' $f)
        if [ "$result" == "$val" ]
        then
            echo "[*] Found pattern [ $val ] in file [ $f ]."
        fi
    fi
done

# done
exit 0

findVal.sh
[!] Usage: findVal.sh <search pattern> <position>

da4d5dc7b5689b9d859bce2ba90107f5
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Pattern searching inside Variable - not looking at files

Hi, I've searched this site and not found this already, so if I missed on my search, sorry. I need to pass in a variable to a script, where the first three characters of that variable represent a calendar quarter, and the last 2 characters are the year. I.E. Q0105 for Q1, Q0205 for Q2, and... (3 Replies)
Discussion started by: Rediranch
3 Replies

2. Shell Programming and Scripting

Pattern searching pattern in c files

I have a problem in searching a specific pattern in c files. My requirement: I have to find all the division operator in all cfiles. The problem is, the multi line comments and single line comments will also have forward slash in it. Even after avoiding these comments also, if both... (6 Replies)
Discussion started by: murthybptl
6 Replies

3. UNIX for Dummies Questions & Answers

Searching for files with certain string pattern

Hello All I would like to search for files containing certain string pattern under all the directories under /vobs/vobname and print the output to a file in my home directory. How can I do this? Note: /vobs/vobname conatins several directories. Thank You in advance newbetounix (1 Reply)
Discussion started by: intrigue
1 Replies

4. Shell Programming and Scripting

Searching all files that contain pattern

Hello All, i have to search a pattern in all the files in all subfolders that are present in current directory. suppose i am in d1 directory and in that sd1,sd2,sd3 are subdirectories. in sd1 i have files f1,f2 sd2 i have files f3,f4 sd3 i have file f5 i have to list out all those... (4 Replies)
Discussion started by: ravi.sadani19
4 Replies

5. Shell Programming and Scripting

Searching a pattern in file and deleting th ewhole line containing the pattern

Hi All, Please can someone assist in the script I have made that searches a pattern in a file and delete the whole line containing the pattern. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read value # check if the user has... (1 Reply)
Discussion started by: Shazin
1 Replies

6. Shell Programming and Scripting

Script for searching a pattern in 5 files and deleting the patterns given

Hi All, I have written the below script that searches for the pattern in a file and delete them if present. please can some one have a look and suggest the changes in the script. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read... (4 Replies)
Discussion started by: Shazin
4 Replies

7. Shell Programming and Scripting

Searching across multiple files if pattern is available in all files searched

I have a list of pattern in a file, I want each of these pattern been searched from 4 files. I was wondering this can be done in SED / AWK. say my 4 files to be searched are > cat f1 abc/x(12) 1 abc/x 3 cde 2 zzz 3 fdf 4 > cat f2 fdf 4 cde 3 abc 2... (6 Replies)
Discussion started by: novice_man
6 Replies

8. Shell Programming and Scripting

Searching a particular string pattern in 10000 files

Problem Statement:- I need to search a particular `String Pattern` in around `10000 files` and find the records which contains that `particular pattern`. I can use `grep` here, but it is taking lots of time. Below is the command I am using to search a `particular string pattern` after... (3 Replies)
Discussion started by: raihan26
3 Replies

9. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

10. Shell Programming and Scripting

Searching for a pattern and extracting records related to that pattern

Hi there, Looking forward to your advice for the below: I have a file which contains 2 paragraphs related to a particular pattern. I have to search for those paragraphs from a log file and then print a particular line from those paragraphs. Sample: I have one file with the fixed... (3 Replies)
Discussion started by: danish0909
3 Replies
OPANNOTATE(1)						      General Commands Manual						     OPANNOTATE(1)

NAME
opannotate - produce source or assembly annotated with profile data SYNOPSIS
opannotate [ options ] [profile specification] DESCRIPTION
opannotate outputs annotated source and/or assembly from profile data of an OProfile session. See oprofile(1) for how to write profile specifications. OPTIONS
--assembly / -a Output annotated assembly. If this is combined with --source, then mixed source / assembly annotations are output. --demangle / -D none|smart|normal none: no demangling. normal: use default demangler (default) smart: use pattern-matching to make C++ symbol demangling more read- able. --exclude-dependent / -x Do not include application-specific images for libraries, kernel modules and the kernel. This option only makes sense if the profile session used --separate. --exclude-file [files] Exclude all files in the given comma-separated list of glob patterns. --exclude-symbols / -e [symbols] Exclude all the symbols in the given comma-separated list. --help / -? / --usage Show help message. --image-path / -p [paths] Comma-separated list of additional paths to search for binaries. This is needed to find modules in kernels 2.6 and upwards. --root / -R [path] A path to a filesystem to search for additional binaries. --include-file [files] Only include files in the given comma-separated list of glob patterns. --include-symbols / -i [symbols] Only include symbols in the given comma-separated list. --objdump-params [params] Pass the given parameters as extra values when calling objdump. --output-dir / -o [dir] Output directory. This makes opannotate output one annotated file for each source file. This option can't be used in conjunction with --assembly. --search-dirs / -d [paths] Comma-separated list of paths to search for source files. You may need to use this option when the debug information for an image contains relative paths. --base-dirs / -b [paths] Comma-separated list of paths to strip from debug source files, prior to looking for them in --search-dirs. --session-dir=dir_path Use sample database out of directory dir_path instead of the default location (/var/lib/oprofile). --source / -s Output annotated source. This requires debugging information to be available for the binaries. --threshold / -t [percentage] Only output data for symbols that have more than the given percentage of total samples. --verbose / -V [options] Give verbose debugging output. --version / -v Show version. ENVIRONMENT
No special environment variables are recognised by opannotate. FILES
/var/lib/oprofile/samples/ The location of the generated sample files. VERSION
This man page is current for oprofile-0.9.6. SEE ALSO
/usr/share/doc/oprofile/, oprofile(1) 4th Berkeley Distribution Tue 06 July 2010 OPANNOTATE(1)
All times are GMT -4. The time now is 11:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy