name zip text file to Julian Date - zip

I have a batch file that zips text files and names it as txtfiles-%date%.zip. What I would like to do is change the %date% to julian date. Is this possible? I have no idea how to start. PLease help me.
"C:\Program Files (x86)\7-Zip\7z.exe" a txtfiles-%date%.zip "*.txt"
thank you

have a separate batch script executing the command you gave, but instead of using %date%, use a separate variable defined prior. In this, a simple time/date conversion is possible.

Related

Move files to their respective folder in linux based on the date of the folder and the date of the file

I'm fairly new to bash scripting and linux, and I have a folders with just dates such as
2012-11-20
2012-11-21
2012-11-22
2012-11-23
and I have files with the name data_11202012_randomnumbers_csv.
I would like to create a script that can move every single csv file to it's correct folder by matching the date on the file to the folder.
I've been just typing mv file path but i have 100s of files and I'm wondering if theres an easier way.
Any help would be appreciated.
The following should do it for you. I will explain with comments
for file in your_folder/*; do
# 1. Extract the numbers from the file name
dir="${file#data_}" # remove data_ prefix
dir="${dir%%_*}" # remove everything after first _
# 2. Rearrange the numbers into the desired format
dir="${dir:2:4}-${dir:0:2}-${dir:6:2}"
# 3. Move the file into the directory
mv file dir
done
Here you have a very useful bash cheatsheet where you can learn more about it. It illustrates all the variable expansions I've made in my snippet and more.

Find linux files with similar names but having different date

I have some files named like this:
aaa-bbb-xxx.ext
aaa-bbb-yyy.ext2
aaa-bbb-zzz.ext3
Some of them are of the same date - then I'm not interested in them. I'd like to find only those files which dates (basically, day of editing) differs. How do I find them? Thank you.
Edit: I forgot to mention - all of files are in the same directory, so there is no need to look up for them on the HDD; the only problem is to make a recognition in the following manner:
1. get 3 files matching the pattern
2. check their dates (day basically) of editing
3. if dates are different, list these files; if the same, ignore
4. continue until all files are checked in the directory
Linux command "Locate"
may help you.

Remove Middle Part of File Name in Linux

I've tried lots and lots of variations using the rename command in the Linux command line and nothing happens when I execute these commands - no errors and no expected outcomes. I've tried using the find command to find files and then rename them with no success. I have files that look like this
201901.cdas1.20190101.pgrbh.grb2flxf06.grb2
201902.cdas1.20190102.pgrbh.grb2flxf06.grb2
and I need them to look like this for the script that is expecting a specific file name format 201901.flxf06.grb2 and 201902.flxf06.grb2.
I need to delete the middle part of the file name with a wild card since there are dates that change in multiple files. The deleted part is this: cdas1.pgrbh.grb2
this is not homework and I've been searching the internet most of the day trying to use different options other than the rename option or a for loop since I get a missing } braces error. Thank you!
Assuming you're using the perl rename command:
rename 's/cdas1\.pgrbh\.grb2//' *.cdas1.20190101.pgrbh.grb2*.grb2

Linux bash to compare two files but the second file must be find

I have a batch that integrates an xml file time to time but could happens daily. After it integrates it puts in a folder like /archives/YYMMDD(current day). The problem is if the same file is integrated twice. So I need a script what verifys the file (with diff command its possible but risky to make a bottleneck) but the problem is I can't find to resolve how to make to give the second files location.
P.S. I can't install on the server anything.
Thanks in advance.

Printout result to a file

I am running few scripts to check size of files and folders on ubuntu.
How can i make these scripts automatic so that they might run automatically at start of day and printout result to a text file
i am new to scripting
Please reply
To printout to a text file is fairly simple.
I'm assuming you're using python. Correct me if not.
First, open a txt file with write permissions (the second argument of open).
You can then use the .write() method to write to the file.
Finally, it is good practice to close the file afterward.
f = open('file.txt', 'w')
f.write("Hello world")
f.close()
For script automation, you're going to want to read up on cron jobs: http://en.wikipedia.org/wiki/Cron
actually you can redirect du command's output to file, executing by a cron job. The full shell script is :
#!/bin/bash
du -H >> /tmp/yourfile.log
Notes:
look for du's man page for more information on option flags.
You may want to have variables in file name for separating daily logs
This sounds like a serverfault.com question.

Resources