Bash to rename files repeats previous filename in directory
In the below bash processes substitution, if there are 3 files in a directory /home/cmccabe/medex.logs/analysis.log, the filename variable is set to where these files are located.
The code does execute, the problem is that if there is a renamed file in the output directory below, it gets repeated but the new one does not.
So,lets say that there is a file in the output directory that has been renamed to
when the script executes the second time the output directory looks like:
the renamed file in the directory repeats while the new file being renamed is ok.
However if I execute the script a third time the directory looks like:
I am not sure why the filenames repeat for the previous and do not know how to fix it. Thank you .
text file in /home/cmccabe/Desktop/percent - there could be a maximum of 3 files in this directory
text file in /home/cmccabe/Desktop/analysis.txt
desired result in /home/cmccabe/Desktop/percent
I think it may be the for file in *.txt; do line that is causing the repeats. If there is a renamed file in the directory and a new one is executed then the old file gets renamed as well as the new file.
So if there is a renamed file in the directory
already and a new file gets renamed to 01-0101_Last-First_fbn1_20xcoverage.txt, the original file is repeated in because of that for. I think that is he issue but not sure how to fix it. Thank you .
I added line="$line" under thewhile and using set -x, can see the original file as well as the new file are read into line, but not sure how to only process the new one.
Last edited by cmccabe; 03-27-2017 at 05:59 PM..
Reason: fixed format, updated post
I am trying to use awk to calculate the average of all lines in $2 for every file in a directory. The below bash seems to do that, but I cannot figure out how to capture the string before the _ as the output file name and have it be tab-delimeted. Thank you :).
Filenames in... (3 Replies)
I have a directory e2e_ms_xfer/cent01
this contains the multiple files some of which will be named below with unique date time stamps
e2e_ms_edd_nom_CCYYMMDD_HHMM.csv
What I want to do is in a loop
1) Get the oldest file
2) Rename
3) Move it up one level from e2e_ms_xfer/cent01 to... (1 Reply)
Hi,
I have files with filenames as below.
SGM Daily Sales Email-en-us-05312012.xlwa
I want to rename it in .xls. I am writing a script to change this, as there can be multiple files in subfolders.
I have the following script.
#!/bin/ksh
for oldfile in $(find... (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)
In the Directory all the Files are following format.
Filename_yyyymmdd_numbers.txt
eg.
file_name_20120106_015802.txt .
I want to write the Shell script to rename all the file to
file_name.txt.in the directory.
Thanks
Mani (5 Replies)
Hi,
I've got a large to task to do, which I've broken into three section. I'm just stuck on one of the sections.
I have to change the end of a filename from .txt to .doc in a directory. So if I have a directory called "folder1" and two files contained in it called "file1.txt" and "file2.txt",... (7 Replies)
Hi,
I have around 100 xml file in a directory. I need to rename the files from .xml to .xml1. So i tried using the following command:
mv *.xml *.xml1
but i am getting the following error
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more... (8 Replies)
Hello~
I'm on AIX version 5 and I believe I have the tcsh shell environment to play in. Can you guys help me with a solution to rename all files that have "eclp" in the filename to "ecl" ? I basically want to rename the files and strip the "p" out.
i.e. original filenames:
... (3 Replies)
System: Ubuntu Intrepid Ibex
I'm running webcamd as a sort of "security" program, but I need a script that will archive my webcam.jpg files.
So, take the following file:
/home/slag/www/webcam.jpg
Rename it--preferably with a time stamp.
Place it in say:
/home/slag/www/history/
... (4 Replies)