Sponsored Content
Top Forums UNIX for Advanced & Expert Users shell script to format .CSV data Post 302363078 by tmcmurtr on Monday 19th of October 2009 10:35:36 AM
Old 10-19-2009
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

 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

format csv file using shell script

i have a report.csv file from oracle datavase In that file data is like this with report heading and date SALES DAILY REPORT DATE: 06-26-2007 REPORT NAME: SALES DATA AA.BB.CCCC.DDDD,BBBBB,06-26-2007,0,BEGIN,END ZZ.VV.DDDD.XXXXXXX,MMMMMM,06-25-2007,18,BEGIN,END... (3 Replies)
Discussion started by: raosurya
3 Replies

2. Shell Programming and Scripting

Shell script to format a .CSV data

Hi There I needed to write a Unix shell script which will pick up the data from a .CSV file and reformat it as per the requirement and write it to another .CSV file. Currently I am in the proess of Data Import to "Remedy System" (A one kind of incident mangement Application) and this... (8 Replies)
Discussion started by: Uday1982
8 Replies

3. Shell Programming and Scripting

Exporting data as a CSV file from Unix shell script

Friends...This is the first time i am trying the report generation using shell script... any suggestions are welcome. Is there a way to set the font size & color when i am exporting the data from unix shell script as a CSV file ? The following sample data is saved as a .csv file in the... (2 Replies)
Discussion started by: appu2176
2 Replies

4. Shell Programming and Scripting

Reading the data from CSV and performing search through shell script

Hello, I am working on building a script that does the below actions together in my Linux server. 1) First, have to read the list of strings mentioned in CSV and store it in the shell script 2) Second, pick one by one from the string list, and search a particular folder for files that... (2 Replies)
Discussion started by: vikrams
2 Replies

5. Shell Programming and Scripting

Need perl or shell script to sort vertical lines to horizontal line in csv format

Need perl or shell script to sort vertical lines to horizontal line in csv format My file like below ------------------------- ================================================================================ PATH PINKY1000#I1-1-ZENTA1000-2#I7-1-ASON-SBR-UP-943113845 ... (4 Replies)
Discussion started by: sreedhargouda.h
4 Replies

6. Shell Programming and Scripting

Format CSV file from a shell script

I have a shell script which creates a CSV files. there are 3 fields, field1, field2 and comp. I will generates the values for field1 and field2 and Want to compare both. If field1>filed2 then comp should be success written in green in CSV file, else it should fail in red color. How can I change the... (5 Replies)
Discussion started by: sauravrout
5 Replies

7. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 7 columns having values say column 1,column 2.....column 7 as below along with their values. Name, Address,... (7 Replies)
Discussion started by: Vivekit82
7 Replies

8. Shell Programming and Scripting

Shell script to extract data from csv file

Hi everyone, I have a csv file which has data with different heading and column names as below. Static Data Ingested ,,,,,,,,,,,,Known Explained Rejections Column_1,column_2,Column_3,Column_4,,Column_6,Column_7,,% Column_8,,Column_9 ,Column_10 ,... (14 Replies)
Discussion started by: Vivekit82
14 Replies

9. Programming

Python or Shell script to Grep strings from input file and output in csv format

Hi Experts, I am writing a python script to grep string from file and display output in csv file as in attached screenshot https://drive.google.com/file/d/1gfUUdfmQma33tz65NskThYDhkZUGQO0H/view Input file(result_EPFT_config_device) Below is the python script i have prepared as of... (1 Reply)
Discussion started by: as7951
1 Replies
DANTED(8)						      System Manager's Manual							 DANTED(8)

NAME
danted - network proxyserver SYNOPSIS
danted [-DLVdhnv] [-N number] [-f file] DESCRIPTION
Dante implements the socks standard and can function as a firewall between networks. Dante relays TCP and UDP both from outside the network and in, and from inside and out. The options are as follows: -D Dante will detach from the controlling terminal and run in the background as a system daemon. -L Displays the license Dante comes under. -Nnumber Dante will fork of number copies of itself when starting. Can be used for very busy servers. -V Verifies config file and exits. -d Enables debugging. -ffile Dante will read its configuration from file. -h Shows the currently valid options. -n Disables TCP keep-alive messages. Normally Dante enables TCP keep-alive messages so that connections from machines that have crashed or for other reasons no longer can be reached time out. -v Displays Dante version. ENVIRONMENT
TMPDIR Use TMPDIR for temporary files. Since Dante uses lockfiles it is recommended that TMPDIR be set to a (local) filesystem with low latency. FILES
/etc/danted.conf Dante server configuration file. AUTHORS
For Inferno Nettverk A/S, Norway: Michael Shuldman <michaels@inet.no>: Design and implementation. Karl-Andre' Skevik <karls@inet.no>: Autoconf and porting. SEE ALSO
dante.conf(5) danted.conf(5) Information about new releases and other related issues can be found on the Dante WWW home page at http://www.inet.no/dante. BUGS
See the accompanying BUGS file. New ones should be reported to dante-bugs@inet.no. Feb 17, 2001 DANTED(8)
All times are GMT -4. The time now is 05:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy