Hi,
I have list of directory paths in a variable and i want to delete those dirs and if dir does not exist then search that string and get the correct path from xml file after that delete the correct directory. i tried to use grep and it prints the entire line from the search.once i get the entire line how do i filter the path using awk special variables?
if $i has dir1/kernel if it exists delete otherwise grep "dir1/kernel" from input.xml file read the project name path and delete the folder"abc/dir1/kernel" and continue with loop.No space between name,=," so how do i use FS & what should be the search pattern in awk?
for i in ${REMOVE_DIRS}
do
if [ -d "${i}.git" ]; then
echo "Remove ${i}.git"
rm -rf ${i}.git
else
echo "directory ${i}.git does not exist"
grep "${i}" input.xml >> out.txt
fi
done
I appreciate your ideas .
---------- Post updated at 06:19 AM ---------- Previous update was at 03:42 AM ----------
Here i get the expected output: Word[1]=name=Word[2]=abc/dir1/kernel
word[2] is what i wanted .
From below mentioned code,Problem i have is $abc variable has name="abc/dir1/kernel" so i couldnt split it similar to above mentioned code.I appreciate all your ideas / help.
for i in ${REMOVE_DIRS}
do
if [ -d "${i}.git" ]; then
echo "Remove ${i}.git"
rm -rf ${i}.git
else
echo "directory ${i}.git does not exist"
grep "${i}" input.xml >> out.txt
abc=`awk ' "${i}" { print $2 } ' out.txt`
echo $abc
fi
done
Because of double quotes i am unable to use string in split commented awk works as expected. how do i achieve the same result from the above output(ie $abc) ?
#!/bin/bash
REMOVE_DIRS=`cat List`
# Remove dirs
#if [ -f try.log ]; then
#rm -rf try.log
#fi
for i in ${REMOVE_DIRS}
do
if [ -d "${i}.git" ]; then
echo "Remove ${i}.git"
rm -rf ${i}.git
else
echo "directory ${i}.git does not exist"
# grep "${i}" input.xml >> out.txt
# abc=`awk ' "${i}" { print $2 } ' out.txt`
abc=`awk -F= -v abc="${i}" '$0 ~ abc { print $1 }' input.xml`
echo $abc
# split and remove the dir
#awk 'BEGIN { str="\"abc/dir1/kernel\" path";search="\"";
# n=split(str,array,search);
#for (i=1;i<=n;i++) {
# printf("dirpath[%d]=%s",i,array);
# }
#exit;
#}'
fi
done
First check for presence of dir1/kernel if exists remove it else search the string dir1/kernel in input.xml file and get the output as abc/dir1/kernel from <pro name="abc/dir1/kernel" . once i have new or correct path delete dir abc/dir1/kernel.
---------- Post updated at 02:30 AM ---------- Previous update was at 01:48 AM ----------