LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-11-2013, 12:20 PM   #1
dimitriauxio
LQ Newbie
 
Registered: Sep 2013
Posts: 6

Rep: Reputation: Disabled
Find files that they have the same filename but different extension.


I am writing a script which it searches into a directory for two specific file extensions. An .ear and a .war file. When it finds those files who have those extensions then it should search in the same directory to find if there are any files who they have the same name as the first ones but different extension. This extension is .config. My problem is that I am trying to do it and I think I am doing it wrong. Can someone help me to sort out this problem?

This is the code I have written so far:

for file in $(find /home/user/ftpuser -maxdepth 1 -name "*.[ew]ar" -type f);
do
file=${file%*.[ew]ar}
locate /home/user/ftpuser ${file}.config
 
Old 09-11-2013, 02:01 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Couldn't you just do:
Code:
find /home/user/ftpuser -maxdepth 1 -type f -iname | while read ITEM; do
 case "${ITEM}" in
  *.ear|*.war) if [ -e "${ITEM%.ear}.config" -o -e "${ITEM%.war}.config" ]; then
                  echo got .config
               fi
            ;;
 esac
done
 
Old 09-11-2013, 02:10 PM   #3
dimitriauxio
LQ Newbie
 
Registered: Sep 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks a lot! I will check for it and I'm gonna let you know!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
find before and after log files too, with date-time in filename. rudydark Linux - General 2 05-28-2013 08:14 AM
[SOLVED] Find files with specific extension and move to a directory moyorakkhi Linux - Newbie 10 04-19-2011 09:50 AM
[SOLVED] how can i find the files with extension .h or .c with bash scripts? ddebbie90 Programming 5 02-03-2011 09:51 PM
[SOLVED] How can I find the total disk space used by all files with the same extension (*.dat) respex Linux - Newbie 5 12-04-2009 07:38 AM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 06:55 PM


All times are GMT -5. The time now is 11:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration