I am looking for a way to find a date in the file without using find. for example something like this:
There are a number of files that have 5-28-2014.txt in the name, even one file that is named just 5-28-2014.txt, but I keep getting "no" when the script returns the value. Any ideas?
Also the YEST variable does contain 5-28-2014.txt, I echoed to check it
I am looking for a way to find a date in the file without using find. for example something like this:
There are a number of files that have 5-28-2014.txt in the name, even one file that is named just 5-28-2014.txt, but I keep getting "no" when the script returns the value. Any ideas?
Also the YEST variable does contain 5-28-2014.txt, I echoed to check it
First, note that the two lines marked in red above make absolutely no difference to the following if statement. The variables you define on those lines are not referenced after they are defined.
Second, if we supposed that you have two files named with names containing "txt", say for instance 5-28-2014.txt and txtfile. In this case the 1st line of your script sets the variable files to the value:
The last line in your script then compares this two line value to the string "5-28-2014" and will find (even after changing the = to ==) that the strings "5-28-2014.txt\ntxtfile" and "5-18-2014" are not the same.
Yoda already suggested a way around this assuming you are looking for the date in the file's name. You could also try something like the following for that:
which will work with any shell that recognizes basic POSIX standard shell syntax.
If you're looking for the date as text inside a file, rather than in the file's name, Akshay suggested a way to do that.
This User Gave Thanks to Don Cragun For This Post:
Suppose i have a list of files in a directory as mentioned below
1. Shankar_04152019_ny.txt
2. Gopi_shan_03122019_mi.txt
3. Siva_mourya_02242019_nd.txt
..
.
.
.
.
1000 . Jiva_surya_02282019_nd.txt
query : At one shot i want to modify the above all filenames present in one path with... (4 Replies)
Hello,
I'd like to write a monthly archive script that archives some logs. But I'd like to do it based on yesterday's date. In other words, I'd like to schedule the script to run on the 1st day of each month, but have the archive filename include the previous month instead.
Here's what I... (5 Replies)
Hello,
We have a process on our Linux RedHat machine creating symbolic links and moving around some files from domain to domain. The issue is that the programmer has left a long time ago and nobody knows how the program is called, where it is and how the scheduling is setup. It runs every day for... (7 Replies)
Please help, I want script to check filename, size and date in specify path.
I want output as:
DATE: YYYYMMDD HH:MM
------------------------------------------------
fileA,filesize,yyyy mm dd HH:MM
fileA,filesize,yyyy mm dd HH:MM
fileA,filesize,yyyy mm dd HH:MM
fileA,filesize,yyyy mm dd... (1 Reply)
I am using ksh93 on Solaris.
Ok, this may seem like a simple request at first. I have a directory that contains sets of files with a YYYYMMDD component to the name, along with other files of different filespecs. something like this:
20110501_1.dat
20110501_2.dat
20110501_3.dat... (2 Replies)
Hi all
I have the following question:
With this command, I get the latest file in a directory.
lastfile =`ls -1tr | tail -n 1`
echo $lastfile
The output is then:
partner131210.txt (meaning 13th December 2010)
My goal is to get the date into a variable and to obtain a final variable... (4 Replies)
I am a newbie in shell scripting and I need to produce a script to work and achieve the following:
1) Look into the file /etc/defaultrouter , and store the value in it
2) If the value is a number, go to LIST and print out the second column corresponding to the value.(eg London)
3) If the... (5 Replies)
hello,
can anyone tell me how to rename a filename in a script to contain the current date?
i have searched for the answer but with little success!
many thanks
rkap (4 Replies)