I am trying to use sed to rename all .txt files in /home/cmccabe/test. However, I am getting an error that I seems to be putting the files in a new directory s, instead of in the original. Thank you .
bash
contents of /home/cmccabe/testbefore script executed
contents of /home/cmccabe/testafter script executed (desired output)
Last edited by rbatte1; 03-21-2017 at 10:50 AM..
Reason: Moved a closing CODE tag to make more sense
However, I am getting an error that I seems to be putting the files in a new directory s, instead of in the original. Thank you .
You get the error because this:
is not a valid sed-command. The s-subcommand has the form:
and the last slash at the end leads to a simple syntax error.
Furthermore, your script is about as badly written as can be:
Never do that in a script. Ideally you should use a commandline argument to provide the directory in question, but in absence of this do it this way:
Secondly:
I spare you the obligatory sermon about not using backticks: you have been told this perhaps several dozen times already and i find the insistence to write bad scripts commendable. The POSIX variant of $(...) has only been developed to have something one can safely ignore.
You still may consider to invoke sed only once per run of the script instead of once per file the script encounters:
But even this is just a waste of processing power and other resources, because you can do the same with variable expansion inside the shell, without any external program:
I have files in the ABC_YYYYMMDD.zip format under a directory. Each zip file contains A text file in the ABC_YYYYMMDD.txt format.
I am trying to create a script that will Rename the zip files and their underlying text file replacing the datepart in them with .
For eg: in the case of... (1 Reply)
Dear friends,
I have created a script to rename all files in a directory by appending the file name with username (who created the file), the date it was created. For example, "apple.doc" should be renamed to "johnFeb23apple.doc" where "john" is the owner and "Feb23" is file created date. It... (4 Replies)
Hi.
I don't have any experience with making scripts in bash. I need a simple script to rename all files in a folder to the format file1.avi, file2.avi, file3.avi, and so on.....
Please note that the original files have different filenames and different extensions. But they all need to be... (2 Replies)
I have a file named Me_thread_spell.txt that I want to split into smaller files. I want it to be split in each place there is a ;;;. For example,
blah blah blah ;;;
blah bhlah hlabl
awasnceuir
asenduhfoijhacseiodnbfxasd;;;
oabwcuhaweoir;;;
This full file would be three separate files... (7 Replies)
Okay so here's something that's confusing me: I have a script that's designed to remove the words "new_" from the front of any file except two exceptions and it looks something like this...
for i in new_*
do
if ] && ]; then
j=`echo "$i"|cut -c5-`
mv $i $j
fi
done
... (5 Replies)
Hi,
i need to write a shell script where i have to loop through all the file in a directory and rename them based on below condition.
file1.dat
file2.dat
file3.dat
the above files has to be moved to another directory like below
file1_201001.dat
file2_201002.dat
file3_201003.dat... (3 Replies)
I want to change the name of some of my files (mypics-0001, mypics-0002, mypics-0003.....mypics-0240) and I want to double check to see if this code is right:
x=0
until
do
sed 's/mypics\-*/bday/g'
done
Would this change all of my file names to "bday0001....bday0240"?
Please let me... (0 Replies)
Hi,
Is it possible to rename files at a time in a directory without using the for loop. (ex: intial filename- abc.txt to abc.tmp or abc.txt.tmp)
I need to rename the files in a remote directory to which I'm connecting thru tectia sftp. The commands 'mv', 'for', 'echo' do not work.
I have... (3 Replies)
I'm working on a project that basically unzips three zip files.
When these unzip they create about 70+ directories with subdirectories of year/month with about 3 to 9 pdf files in each directory.
Basically, I'm needing to figure out a way to zip these pdf files up.
for instance the script... (1 Reply)