LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 12-10-2002, 06:20 PM   #1
OrangeWarp
LQ Newbie
 
Registered: Dec 2002
Posts: 1

Rep: Reputation: 0
Batch mv and tr script ...


I've done an extensive search all day and asked a bunch of tech friends with dismal results. Hopefully someone here can be my UNIX hero today.

Ex. directory structure

~/color/red/a.txt
~/color/blue/b.txt
~/color/green/c.txt
~/rainbow/

For simplicity sake my ex. only has 3 different files but what I'm really working on is a HUGE file system with many files I need to analyze later. What I want to accomplish is to create a csh script which will sit in my home directory and automatically pluck out the .txt file from each color subdirectory and drop it into ~/rainbow The script has to specifically pick out the txt files because each subdir has lots of junk in them.

The second thing the script must do is convert the *.txt files using a simple code

Ex. a=1, b=2, c=3

The result after ls ing ~/rainbow should be something like this.

$ls rainbow
1.txt
2.txt
3.txt

I'm thinking I'll definitely need to | stuff, as well as use the xargs command but other than that I'm lost. And maybe there are far easier ways to do this. If you guys can solve this for me it would be a life saver. :-D

Thanks,
OrangeWarp
 
Old 12-11-2002, 05:14 AM   #2
Mik
Guru
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Gentoo + LFS
Posts: 1,316

Rep: Reputation: 46
I don't really know csh scripting but here is a bash script which should get something like that accomplished.

Code:
#!/bin/bash

cd ~/color
for file in `find -name "*.txt"`
do
   dfile=`basename $file`
   dfile=${dfile%.*t}

   case "$dfile" in
     a) prefix="1";;
     b) prefix="2";;
     c) prefix="3";;
     *) prefix="unknown";;
   esac

   cp $file ~/rainbow/${prefix}.txt
done
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch Script to rename files... jamie_barrow Linux - Newbie 16 06-14-2009 01:26 PM
script batch linux cetoute14 Linux - General 5 09-02-2005 07:37 PM
Change batch script to shell script alan.belizario Programming 5 03-31-2005 12:41 AM
Change batch script to shell script alan.belizario Linux - Software 1 03-30-2005 01:49 AM
Help w/ batch/shell script mikehlinuxquest Linux - General 5 09-13-2004 04:41 PM


All times are GMT -5. The time now is 03:17 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration