![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| format file using shell script | balajim | SUN Solaris | 2 | 10-23-2008 09:18 AM |
| format file using shell script | balajim | SUN Solaris | 1 | 10-22-2008 03:30 PM |
| Help writing shell script in c++ format | deadleg | Shell Programming and Scripting | 2 | 03-07-2008 10:08 AM |
| Shell script to format a .CSV data | Uday1982 | Shell Programming and Scripting | 8 | 02-04-2008 05:28 AM |
| format csv file using shell script | raosurya | UNIX for Advanced & Expert Users | 3 | 06-27-2007 08:57 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
shell script to format .CSV data
Hi all,
I have written a shell script to search a specified directory (e.g. /home/user) for a list of specific words (shown as ${TMPDIR}/wordlist below). The script works well enough, but I was wondering if there was a way to display the line number that the word is found on? Thanks! Code:
cat << EOF > ${TMPDIR}/scanit
rm -f ${TMPDIR}/strings
strings "\$1" | egrep -i -f ${TMPDIR}/wordlist >> ${TMPDIR}/strings
if [ -s ${TMPDIR}/strings ]
then
echo >> ${TMPDIR}/${HOSTNAME}.o
echo "File: \$1" >> ${TMPDIR}/${HOSTNAME}.o
file "\$1" >> ${TMPDIR}/${HOSTNAME}.o
cat ${TMPDIR}/strings >> ${TMPDIR}/${HOSTNAME}.o
fi
rm -f ${TMPDIR}/strings
EOF
HOSTNAME=`hostname`
export HOSTNHAME
if [ $# -eq 0 ]
then
echo "You must specify the start of the directory tree to search"
exit
fi
find $1 -type f 2> ${TMPDIR}/${HOSTNAME}_find_errors | tee ${TMPDIR}/${HOSTNAME}_filelist | \
head -100 |\
sed -e "s+^+sh -x ${TMPDIR}/scanit \"+" -e 's/$/"/' > ${TMPDIR}/scanitnow
sh -x ${TMPDIR}/scanitnow 1> ${TMPDIR}/${HOSTNAME}_scan_run 2>&1
cd ${TMPDIR}
if [ -s ${HOSTNAME}.o ]
then
date "+%Y%M%d_%H:%m:%S: indicators found on ${HOSTNAME}" > ${HOSTNAME}_scan_results.csv
cat ${HOSTNAME}.o >> ${HOSTNAME}_scan_results.csv
else
date "+%Y%M%d_%H:%m:%S: No indicators found on ${HOSTNAME}" > ${HOSTNAME}_scan_results.csv
fi
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|