I am new at Linux/UNIX programming. Here is my problem.
I had one big file which I split using the command
csplit -k -s -f april.split. april '/^ISA/' '{10000}'
So now I have multiple files with names
april.split.01
april.split.02
april.split.03
But I need the name of the file like
CHRY.850.01
CHRY.850.02
CHRY.850.03
etc.
Can I use following commands on the prompt or do I have to write a script.
for each in `cat april-850-split`
do
cp $each ${each}.850
Thanks
Yes, you can run this type of stuff from the command line.
You'll get a secondary prompt and it's smart enough to know
you're done when it sees the "done" command.
Preferred, however, is this:
cat april-850-split |
while read each ; do
cp $each $each.850
done
... because then you'll never get the "arglist too long" error.
BTW -- don't think this renaming will give you exactly what you wanted....
don't you need:
number=${each##*.}
mv $each CHRY.850.$number
But again, I prefer doing things like this:
cat april-850-split |
while read each ; do
number=${each##*.}
echo mv $each CHRY.850.$number
done |
tee commands.sh
This'll save my intended "mv" ( rename ) commands in a script file named commands.sh
Then I can visually inspect it --- make sure it's going to do what I want... then run it,
saving all the output to an "err" file:
ksh -xvf commands.sh 2>&1 | tee err
Thanks for your reply. You are correct. I do need CHRY.850.01 etc. When I ran you code, I am getting
mv april.split.03 CHRY.850.
mv april.split.04 CHRY.850.
mv april.split.05 CHRY.850.
without the number.
Here is my code.
$ cat april-850-list | while read each; do number=${each##*.} echo mv $each CHRY.850.$number done | tee repl.sh;
Can you please tell me what is wrong with my code? I ma running on Linux. I don't think that would make a difference.
Thanks
You need to show the contents of the april-850-list file.
What SHELL on Linux?
I'm on Solaris...
We may have to try something like:
number=` echo $each | awk -F. '{print $NF }'`
There is no difference between a script entered on the command line and a script in a file. (Apart from the occasional quoting issue.)
for file in april.split.*
do
mv "$file" "CHRY.850.${file##*.}"
done