11-20-2008
The reason why this doesn't work is simple: in "ls -l $DIR | grep ..." the grep works on the output of ls, not on the files named in this output.
Note, that getting the diskspace and grepping for some content are two entirely different functions. Therefore you could do it only by performing these two different functions on every file and binding together the output of these via a script.
Having said this: use "find" ("man find") to set up a loop and use the "-exec" clause of "find" to 1.) grep the file for the content you are interested in and 2.) use "du" to get the filesize. 3.) Print out both if the grep has found the content, else do nothing. This will give you a list of filenames and -sizes.
I hope this helps.
bakunin
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hello,
iostat -En | grep Vendor | grep -v DV | awk '{print $1 $2}' | sort -u
returns
Vendor:HP
I want to append Disk to it. i.e.:
Disk Vendor:HP
how to do that?
thanks (8 Replies)
Discussion started by: melanie_pfefer
8 Replies
2. Shell Programming and Scripting
Hi All,
I amlearning UNIX scripting. I have a small query. I would be thankful if any one helps me out.
I have a below piece of code which delets the files. If file dosent have the permissions to delete a particular file I have used 2>>operator to track the error code.
But my objective is... (1 Reply)
Discussion started by: manas6
1 Replies
3. UNIX for Dummies Questions & Answers
Hello,
I looking to use grep to return a string with exactly n matches.
I'm building off this:
ls -aLl /bin | grep '^.\{9\}x' | tr -s ' '
-rwxr-xr-x 1 root root 632816 Nov 25 2008 vi
-rwxr-xr-x 1 root root 632816 Nov 25 2008 view
-rwxr-xr-x 1 root root 16008 May 25 2008... (7 Replies)
Discussion started by: MykC
7 Replies
4. Solaris
I have a sun4u system running Solaris 8. I tried running the df command but it returns a blank result. Also I'm unable to collect an explorer from this system as the OS complains that the disk is full. What could be going on here? (10 Replies)
Discussion started by: dperry1973
10 Replies
5. Shell Programming and Scripting
Hi,
I have a problem that I am sure someone will know the answer to. Currently I have a script which returns a binary output if it finds a certain search string (in this case relating to a DRBD cluster) as follows:
searchstring="cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate"
&& echo... (3 Replies)
Discussion started by: almightybunghol
3 Replies
6. Shell Programming and Scripting
Hello,
Thanks in advance for the query.
There is a log file abcd.log which has multible line like this.
"hello1" , "hello2", "hello3" , "hello4" , "hello5"
I want to grep for the lines which has "hello4" & "hello5" and use "hello2" to grep the same log file again.
All these should... (8 Replies)
Discussion started by: kzenthil
8 Replies
7. UNIX for Dummies Questions & Answers
Hi all,
Using grep command, i want to find the pattern of text in all directories and sub-directories.
e.g: if i want to search for a pattern named "parmeter", i used the command
grep -i "param" ../*
is this correct? (1 Reply)
Discussion started by: vinothrajan55
1 Replies
8. Shell Programming and Scripting
Main_script.sh
#! /bin/sh
./Sub_script.sh
rc=$?
echo "Return code from Sub_script.sh : $rc"
if ; then
echo "$rc = 991"
echo ""
exit 1
elif ; then
echo "$rc = 992"
echo ""
exit 1
elif ; then
echo "$rc = 0"
echo ""
exit 1
fi (2 Replies)
Discussion started by: duddukuri
2 Replies
9. Shell Programming and Scripting
Hi Gurus,
I need a script to compare two files: sample file like below:
list:
cde,file4
cde,file5
def,file6
def,file7
def,file8
abc,file1
abc,file2
abc,file3
acd,file9
acd,file10
tmp
file1
file2
file3
file4 (12 Replies)
Discussion started by: ken6503
12 Replies
10. UNIX for Beginners Questions & Answers
Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried:
grep -lr "this string" *
but I do not... (3 Replies)
Discussion started by: Circuits
3 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)