$ cat a
cms/images/services_icon_version_2.1/callback.png
cms/cms/images/services_icon_version_2.1/sync.png
cms/cms/images/services_icon_version_2.1
$ sed '/\/[^\/]*\..../d' a
cms/cms/images/services_icon_version_2.1
at the moment i have in put in a file named temp. and i check from another file name key ( this file has all extensions ). and then delete those lines.
for ext in `cat key`;
do sed -i '/[.]'$ext'$/d' temp ;
done
skmdu sorry you were wrong, coz extension can be "mpeg".
i think its not possible to check either its a file or folder without having a list of extensions. so the way ,which i am currently doing, is right, although it creates problems.
but if you have any solution then please let me know. Thanks.
Your input file looks like the o/p of an ls command, so it was just a hint that the find command can display only the directories with the -type option.
yes all these paths exists in a file and i have to read that file and then i have to delete all those lines from that file which represent to files and keep only those lines which represent to folders.
and let me tell you one more thing that these paths are real path and exit on the server.
$cat b.sh
#! /usr/bin/sh
exec<"a" #a is a filename in which list of paths and filenames are there.
while read line
do
if [ -d $line ]
then
echo $line;
fi
done
$ mkdir /tmp/testing_this.txt
$ mkdir /tmp/testing_this.t.t
$cat a
/var/log
/tmp/testing_this.txt
/tmp/testing_this.t.t
/home/rs/5389/autokick.diff
/home/rs/5389/
/home/rs/
$sh b.sh
/var/log
/tmp/testing_this.txt
/tmp/testing_this.t.t
/home/rs/5389/
/home/rs/
sorry to disturb again. the solution is ok but i have got a problem with it.
exec<"tempFile"
while read line
do
if [ -d $line ]
then
echo $line ;
fi
done
this script is ok when i run it alone. but when i use this thing in my other script then i get strange behavior. after completing task it doesn't quit and goes in some loop and i have to press crtl+c to end it.
FILENAME="tempfile"
while read line
do
if [ -d $line ]
then
echo $line ;
fi
done <$FILENAME
Still if you find issue, post your whole script, if possible.
---------- Post updated at 01:54 AM ---------- Previous update was at 01:54 AM ----------
Try with this,
FILENAME="tempfile"
while read line
do
if [ -d $line ]
then
echo $line ;
fi
done <$FILENAME
Still if you find issue, post your whole script, if possible.
ok thanks skmdu. its working fine now. actually i noticed one thing that after exec my "read -ep" command wasn't working properly and was unable to prompt for any input. may be there is some other way to use it. anyhow its working now. thanks.