The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM
Home Forums Register Rules & FAQ 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. Shell Script Page.


Other UNIX.COM Threads You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-17-2004
Registered User
 

Join Date: Sep 2003
Posts: 13
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-17-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
The message is giving you a clue here. Is there any line in any file under /vob/project that contains a line longer than 2048 chars, which is a limit for some Unix commands?

Try this to count the length of lines in your files
Code:
#!/bin/sh

for file in "$@"; do
  echo -e "\nFILE: $file"
  awk '{printf( "%5d: %s\n", length( $0 ), $0 ) }' $file
done
Save this as linelength.sh, make it executable, and run it as
$ linelength /vob/project/*

Cheers
ZB
Reply With Quote
  #3 (permalink)  
Old 06-17-2004
Registered User
 

Join Date: Sep 2003
Posts: 13
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Thank you Bob.

Yes, it looks like there are some files, it returned a whole bunch of results.

Is there any way i can still search by ignoring these.

i ma new to unix.

thank you
siva
Reply With Quote
  #4 (permalink)  
Old 06-18-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
and invoke it as above.

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}
Will do what you want, excluding any file from the search that contains a line longer than 2047 chars.

Cheers
ZB
Reply With Quote
  #5 (permalink)  
Old 06-21-2004
Registered User
 

Join Date: Sep 2003
Posts: 13
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Thanks a lot Bpb.

Looks like the wc -L (-L) option is not there in this version.

just wondering how should i do.

thank you
siva
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 04:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102