Register
It is currently Fri Jul 25, 2014 5:22 am

Check if file contains text, if so run a command


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Apr 29, 2009 3:37 pm   

Joined: Wed Apr 29, 2009 3:27 pm
Posts: 1
I need a script that will check if a given file contains a line of text or any text, and if so run one or more commands, if not then do nothing.

I need this because i cannot get mysqlimport to import more than one line, even with different line terminate characters. I will be able to use this kind of script to make mysqlimport import one line and then have sed delete a line. Thanks a TON in advance. :mrgreen:


Top
 Profile  
 PostPosted: Wed Apr 29, 2009 7:22 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
Code:
#!/bin/bash
FILE='/etc/rc.conf'
if [[ -s $FILE ]] ; then
echo "$FILE has data."
else
echo "$FILE is empty."
fi ;

FILE='/home/crouse/test.nothing'
if [[ -s $FILE ]] ; then
echo "$FILE has data."
else
echo "$FILE is empty."
fi ;

exit 0




Code:
[crouse@Jughead scripts]$ sh test.sh
/etc/rc.conf has data.
/home/crouse/test.nothing is empty.
[crouse@Jughead scripts]$ touch /home/crouse/test.nothing
[crouse@Jughead scripts]$ sh test.sh
/etc/rc.conf has data.
/home/crouse/test.nothing is empty.
[crouse@Jughead scripts]$


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP