Are the sizes of the "date only" file always smaller than the other files? So, can we not use size of file for the criterion? Then we do not have to worry about all possible file contents.
error correction in red
Let's assume your "empty files" are never larger than 20 bytes. You pick the number.
Be sure to leave the spaces in those commands.
Note: the use cat is intentional, we just want a number.
Last edited by jim mcnamara; 08-21-2012 at 05:31 PM..
Reason: wc -l changed to wc -c
Yeah the date only file is smaller but the other file sizes may vary.
Can it be done by sed or awk command.
get head -1 and then check if the record is like YYYYMMDDHH:MM:SS or get only first 8 characters from the first record and see if it is YYYYMMDD ?
Yes, it can be done by: "sed", "awk", "grep" and probably some dozen other utilities, but that is not the point. The point is, you - you - have to come up with a definition of what constitutes an "empty file" versus an "other file". We can help you put that definition into code, but we can't do the definition for you, because we do not know your input as well as you do.
Let's see: Your empty files have only one lines, whereas other files have several lines, yes? (I don't really know this, i just deduce from your samples and might as well be wrong. Bottom line is, you will have to decide for yourself, ultimately.) This could be tested with
If this gives a value greater than 1 then it is an "other" file, otherwise it might be both.
Next: if it is an empty file it has a time stamp of a certain form at the beginning of the line, so we can match it:
This will return 0 if the expression (your sample timestamp as a regexp) is true and your file is an empty file, otherwise it will return "$? > 0" and your file is an other file.
Couple these checks and in all likelihood you will do it correctly provided that your samples were significant for your input data. If there are other things distinguishing one class of files from the other than work some checks for these into your script so that you raise the chance of correct answers.
i try to set linux date & time in specific format but it keep giving me error
Example :
date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01"
or
date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01"
keep giving me this error :
date: invalid date ‘19-01-2017 00:05:01'
Please use CODE tags... (7 Replies)
Hi,
I have a requirement to create a shell script(tcsh) that finds all the files in a directory having the file name containing date format "YYYYMMDDHHMM" and extract the date time part ""YYYYMMDDHHMM" for further processing.
Could you please have any idea on this.
trades_201604040000.out... (6 Replies)
Hi Unix Gurus,
I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
hi there
I have file names in different format as below
triss_20111117_fxcb.csv
triss_fxcb_20111117.csv
xpnl_hypo_reu_miplvdone_11172011.csv
xpnl_hypo_reu_miplvdone_11-17-2011.csv
xpnl_hypo_reu_miplvdone_20111117.csv
xpnl_hypo_reu_miplvdone_20111117xfb.csv... (10 Replies)
Hi All,
We are copying all the files into ARCHIVE directory after we process them. We are doing this process from last 2 years, now we have a lot of files in ARCHIVE directory.
Now I need to find when the first file is copied into this directory?
If I Issue,
ls -l /ARCHIVE/*.* | tail -1... (3 Replies)
I need to increment a date value through shell script.
Input value consist of start date and end date in DATE format of unix.
For eg.
I need increment a date value of 1/1/09 to 31/12/09 i.e for a whole yr.
The output must look like
1/1/09
2/2/09
.
.
.
31/1/09
.
.
1/2/09
.
28/2/09... (1 Reply)
I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd.
The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4".
This is what I use to change the format:
sed -i '' -e... (2 Replies)
I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column.
I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this?
Sample input
02/27/09,23:52:31
02/27/09,23:52:52... (3 Replies)
Hi ,
I have written a shell script that takes the current date on the server and stores it in a file.
echo get /usr/home/data-`date '+%Y%d'`.xml> /usr/local/sandeep/GetFILE.ini
I call this GetFILE.ini file from an sftp program to fetch a file from /usr/home/ as location. The file is in... (3 Replies)
hi,
for reading a cobol indexed file i need to convert "mmddyy" date format to "ccyyddd" format.
i checked the datecalc and other scripts but couldnt modify them to cater to my need:(...
The datecalc gives an output which i believe is the total days till that date, but i want to convert it... (2 Replies)