Click to See Complete Forum and Search --> : variable from sed


Architect
06-21-2005, 10:37 AM
I have a list that contains several filenames with a .java extension.
I want to convert the .java part to a "();" and then check if this line is present in another file.
To do this I need to get the sed output into a variable. this is the code snippet I am using. for var in $fileList; do
if echo "$var" | egrep -q "\.java" ; then
tcName= $(`echo $var | sed -n -e s/\.tc/\(\)\;/`)
echo "from here" $tcName
fi
done
I am not getting anything in the variable right now with the above code.

How do i do this?

Architect
06-21-2005, 10:55 AM
Actually what I need to do is,
I have a file containing all the Java filenames as functions i.e. ".java" is replaced with "();" in the main file. There are thousands of files there.
I want to know if all the .java files are actually present in a specific directory as well.

I mean the the main file is correct. I need to check that all the files are really present, what would be the best way to verify this?

ph34r
06-21-2005, 11:06 AM
This may work. Get all "words" in your main java file into a temp file, one "word" per line.
Then get a list of just function names, then loop thru them looking for name.java. My syntax on the if/then may not be right.. check it to make sure it is doing the "not a file" part correctly.


for i in `grep () mainfile.java`
do
echo $i >> atmpfile
done
for i in `grep () atmpfile`
do
fname=`echo $i | cut -f 1 -d ( | sort | uniq`
if [ ! -f $fname.java ]
echo $i.java missing
fi
done

Architect
06-22-2005, 06:06 AM
Ok I will try that out.
Anyway how do I get sed's output into a variable?

bwkaz
06-22-2005, 06:32 PM
Anyway how do I get sed's output into a variable? Instead of putting backticks inside $(...), you get rid of one or the other.

Either use backticks, or use $(...). Don't nest them with each other unless you intend to do two process substitutions. (Heck, don't nest backticks inside backticks either, unless you intend to do two process substitutions.)