I have few log folders in directory (FILE) and i need to perform sed on each files inside each folders. Here is my script, and i wish to rename each file back to the same file name after modification. Can anyone guide me on my script below?
1) I don't understand your need to take the basename of the original file. Not to mention that you dont use the variable. Also, given your examples both indicate that the files have the suffix .log it seems removing .txt seems wrong.
2) If $toclean.txt is really just a temp file, then it is better to create a temporary file in /tmp than to use some form of the original filename. For example:
The name makes some previsions to avoid collisions if more than one instance of the script is running concurrently, and all temp files can be easily cleaned up with one rm command at the end.
3) It appears you are trying to overlay the original file, however since the sufix wasn't stripped from the original name you'll end up with something line path/file.log.log
Further, it's not a good idea to overlay the file directly (in my opnion). Disk fill, and other things causes commands to incorrectly generate, or fail to generate, output, so until you are sure that the command was successful, I'd write the second output to another temp file and check the return code. If the return code indicates success, then move the tmp file to the original file.
Finally remove any temp files that you created. Assuming all were created with the example name above:
Hope this helps you move forward.
Hi Folks -
I'm trying to build a simple for loop to accept params and then delete the folder & files on the path older than 6 days.
Here is what I have:
Purge () {
for _DIR in "$1"
do
find "${_DIR}"/* -mtime +0 -exec rm {} \;
done
}
I would be passing... (4 Replies)
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
# rename classified
cd /home/cmccabe/test
pattern2_old="_classify"... (2 Replies)
Hi, I'd like to loop an action over all files with given extension within a folder.
The "main" action is: awk -F "\t" 'BEGIN{OFS="\t"}{if ($10=="S") print$0; }' input.txt > output.txt
The input.txt should be every file in the folder with *.subVCF extension; and the output should be a file... (3 Replies)
Dear folks
I have two data set which there names are "final.map" and "1.geno" and look like this structures:
final.map:
gi|358485511|ref|NC_006088.3| 2044
gi|358485511|ref|NC_006088.3| 2048
gi|358485511|ref|NC_006088.3| 2187
gi|358485511|ref|NC_006088.3| 17654
... (2 Replies)
Guys,
I have a requirement as below.
consider,if i use df command, its getting the below output.
file system kbytes used avail %used Mounted on
/dev/sample/ 45765 40000 5765 50% /
/dev/filesys/ 30000 20000 1000 80% /u
....
....
Now i wanted to cut the /u... (11 Replies)
Hello,
I do have several files in one folder each file contains measurement data.
for each file I would like to replace the character "," by "." ?
How can I do this and how can I do this for each file at once?
E.G. data_1.dat, data_x.dat (original version)
data_1out.dat, data_x_out.dat... (10 Replies)
Hi All,
Need a for loop which should run for number of files in a folder and should pass the file name as parameter to another shell script for each loop.
Please help me.
Thanks. (2 Replies)
Hello,
I am new to shell scripting and stuck on renaming files in a folder. The files have the format
chp01_00001.wav
chp01_00002.wav
....
chp02_00001.wav
chp02_00002.wav
....
but I want them to have the following names:
chp_bloomy_00001.wav
chp_bloomy_00002.wav
chp_bloomy_00003.wav... (8 Replies)
I have a text file which contains lines in this format - it contains 105 lines in total, but I'm just putting 4 here to keep it short:
58571,east_ppl_ppla_por
58788,east_pcy_hd_por
58704,east_pcy_ga_por
58697,east_pcy_pcybs_por
It's called id_key.txt
I have a sample folder called... (9 Replies)
I have a large CSV files (e.g. 2 million records) and am hoping to do one of two things. I have been trying to use awk and sed but am a newbie and can't figure out how to get it to work. Any help you could offer would be greatly appreciated - I'm stuck trying to remove the colon and wildcards in... (6 Replies)