944,126 Members | Top Members by Rank

Ad:
Feb 8th, 2007
0

what's wrong with this ?

Expand Post »
Hi.

I need to write a short script that's looking for a C files in a directory (based on whether it has a semicolon in it and a comment // or /*), check if the file ends with .c and rename it if it doesn't.
I'm pretty much new at this. i wrote this script but it doesn't seem to create the new file with the .c extension.

any input on why would be greatly apreciated.

#!/bin/bash
listOfFiles=`ls $1`
for file in $listOfFiles
do
semi=`grep ";" "$1/$file"`
slash=`grep "//" "$1/$file"`
if [ "$semi" != "" ]
then
if [ "$slash" != "" ]
then
extension=`echo $file | grep ".c$|.h$"`
if [ "extension" == "" ]
then
mv $1/$file $1/$file.c
fi
fi
fi
done
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yaeli_17 is offline Offline
4 posts
since Aug 2006
Feb 13th, 2007
0

Re: what's wrong with this ?

try:
Shell Scripting Syntax (Toggle Plain Text)
  1. #
  2. find $1 -type f -exec grep -l -e '/*' -e '//' {} \; |
  3. while read file
  4. do
  5. grep -q ';' $file
  6. if [[ $? -ne 0 ]] ; then
  7. echo $file | grep -q -e '\.c$' -e '\.h$'
  8. if [[ $? -ne 0 ]] ; then
  9. mv $file "$file".c
  10. fi
  11. fi
  12. done
Reputation Points: 62
Solved Threads: 10
Junior Poster
jim mcnamara is offline Offline
179 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Big Favour!!!
Next Thread in Shell Scripting Forum Timeline: Script to download file using wget





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC