![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reg: Search for a directory | Rajanikanth | Shell Programming and Scripting | 8 | 01-10-2008 02:06 AM |
| Reg: Search for a directory | Rajanikanth | UNIX for Dummies Questions & Answers | 1 | 01-07-2008 02:36 AM |
| Reg: Search for a directory | Rajanikanth | Shell Programming and Scripting | 0 | 01-07-2008 02:30 AM |
| Need to search and replace in multiple files in directory hierarchy | umen | Shell Programming and Scripting | 3 | 12-24-2007 12:56 AM |
| search for certain word in a files from directory | legato | UNIX for Dummies Questions & Answers | 1 | 10-31-2006 02:35 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
search all files and sub directory
I wanted to search in all the sub directories under /vob/project (recurse) in everything inside /vob/project.
search.run for x in `cat search.strings` do find /vob/project -type f -print | xargs grep -i $x > ~/$x.txt done search.string hello whoami I am getting the error Maximum line length of 2048 exceeded. Thanks for any help |
| Forum Sponsor | ||
|
|
|
||||
|
The script will post the length of all lines in all files, regardless of length. To find the lines longer than 2047 chars, try
Code:
#!/bin/sh
for file in "$@"; do
awk -v f=$file '{ if ( length( $0 ) > 2047 ) {
printf( "%s %5d: %s\n", f, length( $0 ), $0 );
}
}' $file
done
If you have a newer version of wc you can try wc -L /vob/project/* (captial L) to show the length of the longest line in each file. So, assuming your wc supports this, Code:
#!/bin/sh
MAX_LINE=2047
TEMPFILE=/tmp/out.$$.txt
# first, create temp file with list of files + max line lengths
find . -type f -print | xargs wc -L | grep -v total >> ${TEMPFILE}
while read term
do
while read line
do
max_line=$(echo $line | awk '{print $1}')
filename=$(echo $line | awk '{print $2}')
if [ "$max_line" -lt "$MAX_LINE" ]; then
echo "$filename:" >> ~/$term.txt
grep -i "$term" $filename >> ~/$term.txt
fi
done < ${TEMPFILE}
done < search.strings
rm -f ${TEMPFILE}
Cheers ZB |
|
||||
|
Substitute
Code:
find . -type f -print | xargs wc -L | grep -v total >> ${TEMPFILE}
Code:
for file in $(find . -type f -print)
do
linecount=`awk 'BEGIN { f=0 } {if ( length( $0 ) > f ) { f = length( $0 ); }} END { print f}' $file`
string="$linecount $file"
echo "$string" >> ${TEMPFILE}
done
Cheers ZB Last edited by zazzybob; 06-21-2004 at 03:42 PM. |
||||
| Google The UNIX and Linux Forums |