I'm trying to run a simple shell program to change all the files named *.cvs to *.txt. I am trying to use WHILE and this is what I have so far:
Quote:
$ while [ $filename ]
> do
> mv $filename `basename $filename .cvs`.txt
> done
This changes the first file from *.cvs to *.txt, but it is not cycling through the other files.
My suspicion is that I don't have the right WHILE [CONDITION], but since I haven't used WHILE before I'm not sure how to do something like while [ $filename!=*.txt ] (psuedo code). Also, I am by no means tied to the WHILE command, if someone knows another command to do this I'd like to know.
I should've mentioned but I'm using the bash shell so I get errors when I try your solution. What would be the bash equivalent? Also, is there a way to do it with WHILE (just out of curiousity)?
Also, is there a way to do it with WHILE (just out of curiousity)?
Yes, there is. The basic operation is to read a stream of data one line at a time and assign the content of the line to a variable:
You can also split the line into several pieces if you name several variables afer the read statement. The splitting is done at word boundaries (white space). If you have fewer columns than variables the last variables are empty, if you have fewer variables than columns the last variable gets the remainder of the line:
So the only thing left is to create the data stream to pour it into the loop. This is done with a "pipeline":
This would rename "a.csv" to "a.csv.txt" which is not exactly what we want. We have to first cut off the ".csv" and only then add ".txt":
To show you an example for what a loop with multiple variables can do: You want a list of filenames like in "ls -l" but only the filenames and the sizes. Lets examine the output of "ls -l" :
We only want the 5th and the 9th column. most people would (mis-)use awk for that, but its a lot simpler:
I have a bunch of files, they have spaces! I am working in windows 7, but I am hoping I could install and use cygwin or some other unix platform to rename my files (suggestions welcome).
The files are named:
Wind Attn Vol - 474.wrl
Wind Attn Vol - 475.wrl
Wind Attn Vol - 476.wrl etc..
I... (10 Replies)
Hi
i want to list files based on date and change the date alone in the files in a directory
abc20120101.txt
xyzxyxz20120101.txt
ccc20120201.txt
ddd20120301.txt
In the above i want to select only files having date 20120101 and rename the date for those files like below
abc20111231.txt... (3 Replies)
Hi guys,
I have a variable where i am storing the filename (with full path).
I just need the value before ".txt". But instead of getting the filename i am getting the contents of the filename.
FileName=/appl/data/Input/US/Test.txt
a=`awk -F"." '{print $1}' ${FileName}`
echo $a... (3 Replies)
Hi,
i have files which contains list of csv file names
say temp.txt contains below like data
Dns_bangalore_08172011.093033.1139.csv
Dns_bangalore_08172011.093133.1139.csv
now i want to insert some string before .csv in the filename
say i want to insert string _sim1 beofre .csv... (3 Replies)
Dear All,
Please help !
i ham having 300 file with E.G. PMC1_4567.arc in seq. like PMC1_4568.arc,PMC1_4569.arc ...n and so on.. i want all those file to be rename like PMC_4567.arc ,PMC_4568.arc .. mean i want to remove 1 from first file name ..
pls help.. (6 Replies)
i have several thousand files and in subdirs that are named
file.46634.txt
budget.75346.pdf
etc
i want to remove the number but retain the extension.
it is always a 5 digit.
thanks. (6 Replies)
I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
ok, this one is definitely too hard for my shell-script-skills.
Hopefully, there is somebody who can help me with this:
I have a folder with files in it named
0.ppm
10.ppm
2.ppm
...
5.ppm
50.ppm
55.ppm
...
355.ppm
360.ppm
etc.
As you will notice, the order in which the files are... (5 Replies)
Hi all,
I am newbie and hope that you can help me to rename a file
If I have a file name Perform.01222006.12345.Log now I would like to backup another file with another name like perform-20060112.dat
This is a flat file, and I want to collect some field, then put it in a new file from... (9 Replies)