LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 11-02-2004, 07:25 AM   #1
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Rep: Reputation: 30
censoring files


hi im trying to make a shell script that censors filenames then moves them to a location if the filename matches one of those names in a case statment.
the program is called censor.sh

so if was to type

./censor move these words please

it would move the files "move" and "words" into a different location

the code i have got so far is:

#!/bin/sh
num=$#
while [ "$num" -ge 1 ]
do

done
exit 0

i know its not much, but im a beginer your help would be much appreciated!
 
Old 11-02-2004, 12:25 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
try something like this:

Code:
#! /bin/ksh
set -A myarray `echo "$@"`
let i=0
while [ $i -lt ${#myarray[*]} ]
do
       if [ -f  ${myarray[i]} ] ; then
            newfile="/new/path/${myarray[i]}"
            mv ${myarray[i]} $newfile
       fi
       let i=$i+1
done
exit
 
Old 11-02-2004, 03:36 PM   #3
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
thanks for the reply, but i couldnt get your code to work, it ran but nothng happend, did you use the korn shell?

i think that it should look something like this? maybe?

#!/bin/sh
num=$#
while [ "$num" -ge 1 ]
do
echo (($1 + 1)) '#this is the line that doesnt work
num=$((num -1))
done
exit 0


./censor this data please
this
data
please


this is how i want it to work, i would use the $1, $2 but you need to specify howmany inputs you are expecting

Last edited by trscookie; 11-02-2004 at 03:38 PM.
 
Old 11-02-2004, 05:25 PM   #4
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
Unhappy Help!!!!!!!!!!!!!!!!!!!

#!/bin/sh
num=$#
while [ "$num" -ge 1 ]
do
echo ${num}
num=$((num -1))
done
exit 0


./censor this data please


ok this loop will count through the words it will now count down like this

1
2
3

but i STILL cant get it to go

please
data
this
 
Old 11-03-2004, 12:01 AM   #5
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
#!/bin/sh
num=$#
files=( $@ ) #Put the arguments in an array
num=$((num -1)) #Must do this because arrays start at 0, not 1.
while [ "$num" -ge 0 ]
do
echo "$num = ${files[$num]}"
#
# You put your move statement here
#
num=$((num -1))
done
exit 0
 
Old 11-03-2004, 07:20 AM   #6
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
hi, thanks for the response but when i run the code it says:

./censored this is a test
./censored: $num = ${files[$num]}: bad substitution


i have also tried : echo "$num=${files[$num]}"
but it say the same thing
i tried echo "$num=$($files[$num])"
and it said;



bash$ ./censored this is a test
./censored: this: command not found
3=
./censored: this: command not found
2=
./censored: this: command not found
1=
./censored: this: command not found
0=

Last edited by trscookie; 11-03-2004 at 07:26 AM.
 
Old 11-03-2004, 01:16 PM   #7
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
for any one wondering i found the answer elseware it is:


#!/bin/sh
while [ $# -ge 1 ]
do
echo $1
shift
done
exit 0
 
Old 11-04-2004, 04:15 AM   #8
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
Quote:
hi, thanks for the response but when i run the code it says:

./censored this is a test
./censored: $num = ${files[$num]}: bad substitution
Humm.. sorry but it works for me.
 
  


Reply



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
Able to write files to MP3 player but no files written into actual device? olnex Linux - Hardware 0 11-11-2005 06:32 AM
How program to read files with extension .dat y .cfg files COMTRADE in fedora 1? ivonne Linux - Software 0 11-22-2004 11:42 AM
How can konqueror view html files in .gz & .bz2 files directly? ailinzhe Linux - Software 5 05-24-2004 08:36 AM
xine plays only (a part of) the sound of a wmv, some divx files and crushes mp4 files bezoomny Linux - Software 1 03-10-2004 07:33 PM
How to filter files in files and files which are in a sub-directory with "grep"? Piero Linux - Newbie 9 08-29-2003 02:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:58 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
Open Source Consulting | Domain Registration