Sponsored Content
Full Discussion: Shell Script Find in File
Top Forums Shell Programming and Scripting Shell Script Find in File Post 302508656 by Pezmc on Monday 28th of March 2011 04:21:39 PM
Old 03-28-2011
Glad I got some things right

I've now updated the code to:
Code:
#!/bin/bash
#set -v
#set -x

case $# in
1)
echo Searching for $1 in '*';
find . -type f 2>/dev/null | xargs grep "$1" -sl 2>/dev/null;;
2)
echo Searching for $1 in $2;
find . -type f -iname "$2" 2>/dev/null | xargs grep "$1" -sl 2>/dev/null;;
3)
echo Searching for $1 in $2 in dir $3;
find "$3" -type f -iname "$2" 2>/dev/null | xargs grep "$1" -sl 2>/dev/null;;
*)
echo =Find in file=;
echo Usage $0 String [FileName] [FileDir];;

esac

Things that don't work as expected
Code:
oak204b:bin john$ fif test '*' /
Searching for test in 2to3 2to32.6 RSA_SecurID_getpasswd a2p a2p5.10.0 a2p5.8.9 aaf_install addftinfo afconvert afinfo afmtodit afplay afscexpand
alias allmemory amavisd amavisd-agent amavisd-nanny amavisd-release ant applesingle appletviewer apply apr-1-config apropos apt etc....

And I still get permission errors
Code:
find: ./.fseventsd: Permission denied
find: ./.Spotlight-V100: Permission denied
find: ./.Trashes: Permission denied

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to Find file size

Hi, I am writing a script which takes the input file name and concat as a new file by appending a "1" to the file name. However i am not able to get the size of this new file. I am not sure where i am going wrong. Please check the script and help me get this working. #!/bin/sh ... (1 Reply)
Discussion started by: ragsnovel
1 Replies

2. UNIX for Dummies Questions & Answers

shell script to find noof characters in a file name

hiiii shell script to find noof characters in a file name, when you run ls -l (using awk) I tried with this ls -l > temp awk -F"," '{print $1 " " expr length $9}' temp but it give some other value instead of file name length (error value like , 563,54,55,56....).How to prnint the... (10 Replies)
Discussion started by: krishnampkkm
10 Replies

3. Shell Programming and Scripting

How to find yesterdays file - shell script

Hey guys - i have a script (below) that searches for current files in a particular directory. However i was wondering how to make it search for "yesterdays" file. For instance it looks for a file from yesterday and no older than that. I used stat command to check for file information: ... (6 Replies)
Discussion started by: DallasT
6 Replies

4. Shell Programming and Scripting

Shell script to find specific file name and load data

I need help as to how to write a script in Unix for the following: We have 3 servers; The mainframe will FTP them to a folder. In that folder we will need the script to look and see if the specific file name is there and load it to the correct table. Can anyone pls help me out with... (2 Replies)
Discussion started by: msrahman
2 Replies

5. UNIX for Dummies Questions & Answers

Shell script find word from one file and insert in another file

Hi, I am new to shell scripting. I need a bash shell scripts which search and grep a parameter value from input.txt file and insert it in between two semicolon of second line of output.txt file. For example The shell script search an IP address as parameter value from input.txt ... (2 Replies)
Discussion started by: sunilkumarsinha
2 Replies

6. Shell Programming and Scripting

How to find invalid URL in a text file using shell script?

How to find and remove invalid URLs in a text file using shell script? (1 Reply)
Discussion started by: vel4ever
1 Replies

7. Shell Programming and Scripting

How to find out the shell of the shell script?

Hello My question is: How to find out the shell of the shell script which we are running? I am writing a script, say f1.sh, as below: #!/bin/ksh echo "Sample script" From the first line, we can say this script will run in ksh. But, how can we prove it? Can we print anything inside... (6 Replies)
Discussion started by: guruprasadpr
6 Replies

8. Shell Programming and Scripting

Shell script to find the sum of argument passed to the script

I want to make a script which takes the number of argument, add those argument and gives output to the user, but I am not getting through... Script that i am using is below : #!/bin/bash sum=0 for i in $@ do sum=$sum+$1 echo $sum shift done I am executing the script as... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

9. UNIX for Dummies Questions & Answers

Find error in the shell script file

echo "******Select Option:******" echo "1 - script1" echo "2 - script2" echo "3 - script3 " read option echo "You have selected" $option"." if then /scratch/username/script1.sh elif then /scratch/username/script2.sh elif then /scratch/username/script3.sh else echo "Please try again... (12 Replies)
Discussion started by: Dish
12 Replies

10. Homework & Coursework Questions

Shell script to find file type

1. The problem statement, all variables and given/known data: Write a shell script that takes a single command line parameter, a file path (might be relative or absolute). The script should examine that file and print a single line consisting of the phrase: Windows ASCII if the files is an... (4 Replies)
Discussion started by: kwatt019
4 Replies
ZGREP(1)                                                      General Commands Manual                                                     ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 02:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy