Social Question

Bilbo123's avatar

How to fetch files' extension from a variable which contains files & folder list in bash script ?

Asked by Bilbo123 (168points) April 29th, 2010

How to fetch the extensions from the below list in bash script ?
variable contains below data: –
A scripts/ A scripts/commit-email.pl.in A scripts/dev01_backup_cleanup A scripts/dir_check A scripts/ftpsync_download A scripts/mysql_table_drop A scripts/mysqlreport A scripts/mysqltuner.pl A scripts/phpinfo.php A scripts/post-commit.pl A scripts/scripts_from_satish/ A scripts/scripts_from_satish/backup, disk & security/ A scripts/scripts_from_satish/backup, disk & security/backup/ A scripts/scripts_from_satish/backup, disk & security/backup/common/ A scripts/scripts_from_satish/backup, disk & security/backup/common/mysql.sh A scripts/scripts_from_satish/backup, disk & security/backup/common/remote_fsys.sh A scripts/scripts_from_satish/backup, disk & security/backup/csrbkp.pnq.net/ A scripts/scripts_from_satish/backup, disk & security/backup/csrbkp.pnq.net/full_bkp.sh A scripts/scripts_from_satish/backup, disk & security/backup/csrbkp.pnq.net/inc_bkp.sh A scripts/scripts_from_satish/backup, disk & security/backup/svn.pnq.net/ A scripts/scripts_from_satish/backup, disk & security/backup/svn.pnq.net/svn_dmp.sh A scripts/scripts_from_satish/backup, disk & security/disk/ A scripts/scripts_from_satish/backup, disk & security/disk/disk_format.sh A scripts/scripts_from_satish/backup, disk & security/disk/disk_load.sh A scripts/scripts_from_satish/backup, disk & security/disk/disk_umount.sh A scripts/scripts_from_satish/backup, disk & security/security/ A scripts/scripts_from_satish/backup, disk & security/security/nessus.pnq.net/ A scripts/scripts_from_satish/backup, disk & security/security/nessus.pnq.net/scan_nw.sh A scripts/scripts_from_satish/check-case-insensitive.pl A scripts/scripts_from_satish/detect-merge-conflicts.sh A scripts/scripts_from_satish/pre-commit A scripts/sendmail_change_from_address.ksh A scripts/services_restarter.sh A scripts/svn post_commit scripts A scripts/tmp/ A scripts/tmp/as A scripts/tmp/ujogodbupdate.sh A scripts/tmp/vmware.sh A scripts/tuning-primer.sh A scripts/ujogodbupdate.sh A scripts/vmware.sh

Observing members: 0 Composing members: 0

8 Answers

rpm_pseud0name's avatar

I know very little about this kind of stuff (very little), but is what you are asking, simply.. what type of file did this information come from? As in, is it a .zip, .exe, .txt, .html, etc… ??

Bilbo123's avatar

This information is in txt file & I want to filter out the words after ”.” character.

rpm_pseud0name's avatar

Then I am not the person for the job. Sorry I couldn’t help.

Akiora's avatar

You should be able to create some kind of regex expression to isolate and extract the characters between ’.’ and ’\n’.

Bilbo123's avatar

Can you please help me in how to do it ?

Akiora's avatar

I don’t know exactly what you’d want for specifics…try looking at wikipedia or this reference for details about crafting regular expressions. Good luck! Hope it helps!

Akiora's avatar

Actually, here is a bash-specific article on the subject.

tuxuday's avatar

f=“abc.txt”
if [[ ”$f” =~ ”\.(.*)$” ]];
then
echo ${BASH_REMATCH[1]}
fi

Answer this question

Login

or

Join

to answer.
Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther