Register
It is currently Thu Aug 21, 2014 12:00 pm

Help with searching for script files


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Sat Oct 30, 2010 1:18 pm   

Joined: Sat Oct 30, 2010 1:01 pm
Posts: 2
Hi,
I need some help with my first bash script.
I have some directories with script files - perl, bash, awk,... and I need to write bash script which will find this files in the entered directory and its subdirectories and then it will display full name and type of the script. The parameter for searching is first line of the file - e.g.: #!/bin/bash

If you enter name of the directory "/home/my/scripts" it should display this:

/home/my/scripts/find.sh bash
/home/my/scripts/bin/server.pl perl
/home/my/scripts/bin/client.pl perl


I was trying "find" and "grep" commands but no succes.

Thanks a lot.


Top
 Profile  
 PostPosted: Sun Oct 31, 2010 9:10 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Examine the 'file' command, in combination with grep you should easily be able to extract the info you're after :)

Code:
~]# file scripts/character/*
scripts/character/character.pm:    Perl5 module source text
scripts/character/struct_test.pl:  a /usr/bin/perl script text


Top
 Profile  
 PostPosted: Tue Nov 02, 2010 6:38 am   

Joined: Sat Oct 30, 2010 1:01 pm
Posts: 2
Thanks for your reply. I'm still trying to put it together but how I said before I'm real beginner in this so I don't have much experiences. :(
Can I ask you for some example how to combine this two commands?


Top
 Profile  
 PostPosted: Thu Nov 04, 2010 4:38 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Code:
file /path/to/my/dir/* | egrep -i '(perl|sed|awk|bash)'


The pipe | symbol diverts the output of the preceding command and places that output as the input to the following command. In this bit egrep -i '(perl|sed|awk|bash)' the pipe | symbol works like an OR.

This will likely not be a full solution for you but maybe you can work out the rest :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP