I have a program that reads in a file and does some parsing to it. The file is generated by another program every night. Due to the ICD the date is part of the file name.
The file name changes every night due to the date change so I am not sure how to have my program change the fileIn name to accommodate this.
If the current fileIn is:
in20120103out.dat
Tomorrow's fileIn is:
in20120104out.dat
filename = Time.now.strftime("in%Y%m%dout.dat")
or
require 'date'
filename = Date.today.strftime("in%Y%m%dout.dat")
strftime means string format for time. The %-parameters are placeholder for Year (Y), month (m), day (d). (There are more placeholders, e.g. year without century...)
You can use the strftime() method to generate the date portion of the filename:
t = Time.now
filename = "in#{t.strftime('%Y%m%d')}out.dat"
And then use the filename variable to open the file as normal.
Related
I have a csv file score.csv with at path /NAS/DQ with 2 columns Scorename,filename.
scorename,filename
ABC,cust.txt
XYZ,bank.txt
These filescust.txt and bank.txt are placed at /NAS/files_path. There will be unique instance of each file placed at this path everyday.
I want to append the file timestamp from /NAS/files_path to /NAS/DQ csv file.
So the timestamp should be updated everytime to the csv file at /NAS/DQ location.
I am new to unix and currently looking for ways to do it.
Any help is appreciated!!
Sed will be a good candidate for this:
sed -ri '2,$s/(^.*$)/\1 '$(date)'/' filename
Substitute the existing line for the existing line plus a space and the date. The format of the date can be amended as required with +%.. We don't want to format the first line, so run the amendments from lines 2 to the last line ($)
I'm working on the CSV again!! I'm trying to get Cucumber to open it, but my problem is, everytime I download a new CSV from the webpage being developed, it adds a date and time stamp like so:
company_123456_export_all_20151007_074608.csv
Is there a way I could tell Cucumber to just open the last one? I've tried:
File.open(C:/Users/**/Downloads/company_#{export}_export_all_*.csv).last
But it doesn't like it, any suggestions?
I think you should read more about file manipulations in ruby.
For your situation you could try something like:
file_name = Dir.glob("C:\/Users\/**\/Downloads\/company_#{export}_export_all_*.csv").last
file = File.open(file_name, "r")
...
Where, first line is getting all file names and takes only last one. And second line is opening this file in read only mode.
Problem: Rename the file to “Result_[timestamp].csv”, where timestamp has format yyyymmddhhmmss
The file is on D:/path/mytest.csv
Thanks!
Look at the MoveFile method of the FileSystemObject or the Name property of the File object. For example:
CreateObject("Scripting.FileSystemObject").MoveFile strOldFileName, strNewFileName
Or:
CreateObject("Scripting.FileSystemObject").GetFile(strOldFileName).Name = strNewFileName
As for formatting the date, see this post from earlier today.
Good luck.
I tried to append the current day and time to the existing file name in shell scripting and I found my command is not working as expected.
For example, if my file name is f1.log and I nees to append it along with current time. This appended version must be used for further processing of the file.
I tried with the following script but getting an error
now=$(date +"%m-%d-%Y/%T")
echo hi >>time.log
mv "time.log" "time.$now.log" (error here : file or directory not found)
echo hello >> time.log$now (have to continue processing with new file)
You cannot have a / character in a filename. The mv command is looking for a directory named with the minute, day, and year of the output of date and trying to create a file named by the time. Just change your format to not include / in the filename.
The problem is with shell's interpertation of / in your date +"%m-%d-%Y/%T".
Change it to a - instead (or something else, as long as it's not / or another meta character that will make the files difficult to work with in the future)
I want to compress a file with name ASCOnnect200_V5.0.0.0_09_Dec_11.zip. I it possible with winrar/rar?
The file name ASCOnnect200_V5.0.0.0_ will be always constant and the date part will be in the format dd-mmm-yy.
In cmd:
rar.exe a -ag+YYYYMMDD arc {FolderName}
The answer is in this forum :)