Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-07-2006, 01:09 PM   #1
LQ Newbie
Registered: Oct 2004
Location: India
Distribution: RHL 9.0
Posts: 22

Rep: Reputation: 15
Question Linux/Unix script for file pattern matching

Hello all,
In my project I have some entities and files corresponding to them. I need to copy each {Entity} file to a directory named {entity-dir}. A small example is:
for entities: xxxxData_Itemxxxx.xml
to the directories

I was able to copy the files but there is a small problem with file-name pattern matching. When I search the pattern, let's say, for 'Item', it copies the file name xxxxData_Itemxxx.xml and xxxData_ItemBomxxxx.xml in the same directories, but I want them to go to different dirs.
Also the order is important,
(xxxx here is any characters that can appear before and after the entity name).
Please help me with pattern-matching.
Thanks & Regards,
Varun Narang
Old 08-07-2006, 02:14 PM   #2
Senior Member
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
This should work. I haven't tested, though, so try first with fake data and files:
for f in xxxxData_*xxxx.xml; do
  d=$(sed 's/^xxxxData_\(.*\)xxxx\.xml$/\1/' <<<"$f" | tr '[A-Z]' '[a-z]')
  [ ! -d "$d" ] && (mkdir "$d" || exit 1)
  mv "$f" "$d"


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
bash script pattern matching thedude2010 Programming 9 06-02-2006 03:39 AM
Perl pattern matching in VB rigel_kent Programming 1 05-30-2006 12:00 PM
Perl Pattern Matching Question pete1234 Programming 2 08-27-2005 11:26 AM
Pattern Matching Help in Bash script cmfarley19 Programming 1 04-07-2004 10:22 AM
pattern matching in perl ludeKing Programming 9 04-02-2004 10:53 AM

All times are GMT -5. The time now is 04:28 AM.

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