|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
A string in a binary file
hi experts,
anyone knows how can i find a string in a multiple binary files in a multiple directories and display the file name containing the string? i mean i have lots of folders with binary files and i am looking for specific string within one of these files i would like to know the right syntax to use for this kind of search, i know i should run strings or something similar. OS Solaris 10 sparc |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
grep $STRING $(find /root_path -type f) Or if that returns too many arguments Code:
for i in $(find /root_path - type f) ; do grep $STRING $i && echo $i;done Of course you can reduce the search space by adding a -name =\*.o parameter or similar to the find command Unfortunately Solaris grep does no support the -r flag as far as i know |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
i used the first code and got Code:
bash: /usr/bin/grep: Arg list too long i am trying to find a string SRV6000 and another string srv6000, i would like to know which file contain this string most probably will be a binary file in the machine. |
|
#4
|
|||
|
|||
|
Quote:
Code:
#!/bin/ksh
# Usage: st_gr_pr pattern file...
pattern="$1"
shift
for f in "$@"
do if [ $(strings -a -n ${#pattern} "$f" | grep -ic "$pattern" ) -gt 0 ]
then printf "%s\n" "$f"
fi
doneand make it executable using the command: Code:
chmod +x $HOME/bin/st_gr_pr Note that the -i option to the grep command in this script makes searches for alphabetic characters case insensitive. I use ksh, but bash should also work if you want to use it in this script. Then run the command: Code:
find . -type f -exec st_gr_pr 'srv6000' {} +to get a list of all regular files rooted in the current directory that contain srv6000 , SRV6000 , or any of the other six strings with combinations of uppercase and lowercase s, r, and v in that order. Obviously, replace srv6000 if you want to find files containing a different pattern. Last edited by Don Cragun; 01-29-2013 at 11:29 AM.. |
| The Following User Says Thank You to Don Cragun For This Useful Post: | ||
q8devilish (02-05-2013) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Code:
bash: /usr/bin/grep: Arg list too long Maybe man xargs will help you? |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Solaris 10 may also have ggrep (i.e. GNU grep - depending on the actual Update of Solaris 10) under /usr/sfw/bin. Code:
$ uname -rsv
SunOS 5.10 Generic_147441-01
$ cat /etc/release
Oracle Solaris 10 8/11 s10x_u10wos_17b X86
Copyright (c) 1983, 2011, Oracle and/or its affiliates. All rights reserved.
Assembled 23 August 2011
$ /usr/sfw/bin/ggrep -a -l "GNU" /usr/sfw/bin/ggrep
/usr/sfw/bin/ggrep
$ /usr/sfw/bin/ggrep -a "GNU" /usr/sfw/bin/ggrep
%s (GNU grep) %s
$ /usr/sfw/bin/ggrep "GNU" /usr/sfw/bin/ggrep
Binary file /usr/sfw/bin/ggrep matchesAs you can see, you can use the -a option to treat all files as ascii text, and -l to just list the filename that matches. Leave off the -l to print the actual line that matches. Cheers, ZB |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Quote:
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert binary file to csv and then back to the binary format | digidax | Shell Programming and Scripting | 7 | 12-27-2012 12:34 PM |
| split a string and convert to binary | srinivasayedla | Shell Programming and Scripting | 5 | 09-09-2011 11:05 AM |
| Insert string in binary file at top | param_it | UNIX for Advanced & Expert Users | 4 | 05-31-2011 06:15 AM |
| Split a binary file into 2 basing on 2 delemiter string | Averell | Shell Programming and Scripting | 1 | 10-30-2008 08:35 AM |
| replace string in binary file | sg1207 | Shell Programming and Scripting | 2 | 07-28-2004 11:26 PM |
|
|