Hour display format

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Hour display format
# 1  
Old 07-11-2016
Hour display format

Hello Sir/Madam,

I'm using Putty utility to run a shell script. I found HOUR display in two positions in UNIX. Is it possible to display in four positions?

File name example: my file name is: HourlyData_20160708_1400.txt

I'm in the process of comparing current date and time with the file I receive..
my objective is to load the data from the file when date & time has a match

Please suggest how I can achieve that via UNIX shell scrip?


Regards,
Vani Sonti

---------- Post updated at 02:42 PM ---------- Previous update was at 01:08 PM ----------

as requested, here is my shell script ( ps: it's not tested yet )


Code:
#!/bin/sh
# Vani Sonti
# shell script date -  07/11/2016 
# commented field code has not been added to this script yet.. 
#fDt=  #- use awk function to trim date from the file name
#fTm= #-- use awk funciton to trim hour from the file name
# hour must be HHHH mode in order to match
dt=`date +"%Y%m%d"`
echo "$dt"
tm=`date +"%H"`
echo "$tm"
filenm = `HourlyData_20160708_1500.txt`
echo "$filenm"
while true
do
 if 
[[ $dt = $fDt && $tm = $fTm ]] then 
# call sqlloader process to parse the file
else
echo no matching file found 
fi


Last edited by V1l1h1; 07-11-2016 at 04:25 PM..
# 2  
Old 07-11-2016
Like this?

Code:
FILENAME_WANTED="HourlyDate_$(date +'%Y%m%d_%H%M').txt"
FILENAME_CURRENT='HourlyData_20160708_1500.txt'
if [ "$FILENAME_WANTED" == "$FILENAME_CURRENT" ]; then
   sqlloader $FILENAME_CURRENT
fi

And please notice, that single quotes '...' or double quotes "..." are valid for string encapsulation, but backticks `...` are not. Backticks - which you used in your example - are used for command substitution.

The following is string encapsulation(string is assigned as written):

Code:
filenm='HourlyData_20160708_1500.txt'



The following is command substitution(executes the command date and puts the output in its place):


Code:
tm=`date +"%H"`
tm=$(date +"%H")

The notation of the two lines result in the same effect. The first is the historical one. The seconde is the newer bash-form. I prefer the latter and never use backticks because of the likeleyhood of confusion to mix the similar looking quotes.


And please notice also that there are no space allowed in variable assignment before and after the equal.

Example:

This is bad(Produces Error "filename": command not found):

Code:
filename = 'HourlyData_20160708_1500.txt'

This is also bad(Assigns empty value to variable filename and produces Error 'HourlyData_20160708_1500.txt' command not found):

Code:
filename= 'HourlyData_20160708_1500.txt'

This is good:

Code:
filename='HourlyData_20160708_1500.txt'


Last edited by stomp; 07-11-2016 at 08:02 PM..
# 3  
Old 07-11-2016
Appreciate your response. Currently i'm invoking shell script using Putty utility so ECHO is helping me to find errors.. I'm new UNIX and not completed tested the script. I'll correct the code based on your examples..

For this project, I'll receive 24 files a day.. (basically one file on top of the hour ).. for that sake I'm trying to compare date and time separably to determine if a match found for those two variables.. if so, load that file.. if not, ignore the load
will I be able to address that with what you described?
# 4  
Old 07-12-2016
Quote:
Originally Posted by stomp
Like this?

Code:
FILENAME_WANTED="HourlyDate_$(date +'%Y%m%d_%H%M').txt"

... ... ...
Hi stomp,
Given that V1l1h1 wants the hour followed by 00 instead of followed by the current minutes value, we'd need to replace the %M in the date format argument with 00. And, it is also possible to put the entire string formatting in the date format. Some people find it easier to read this way although the results are the same:
Code:
FILENAME_WANTED=$(date +'HourlyDate_%Y%m%d_%H00.txt')

# 5  
Old 07-12-2016
Don - thank you for your suggestion .. I'm modifying shell script to see if it works.. I'll post the results shortly..

In the meantime, how to determine current file.. form the attached list?
Hour display format-file_list_for_this_projectpng
# 6  
Old 07-12-2016
one example:
Code:
while read LINE;do
  echo $LINE
done < <(ls Hourly*txt)

# 7  
Old 07-12-2016
Are you sure your's is the right approach? Looking at your sample picture (btw, DON'T post pictures but texts so people can work on it!), you would nearly miss HourlyData_20160711_1700.txt as you only have 8 min to detect it, and HourlyData_20160710_1900.txt would slip through entirely. Wouldn't renaming files, optionally into a different directory, be a viable alternative?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hange display format

I have a file , the file content will be modified regularly , its structure as below, the lines are begins with "A" and "B" . #vi file1 this is testing file A aaaaa B bbbbb A ccccc B ddddd A eeeee B fffff A ggggg B hhhhh I would like to have a script to use the... (3 Replies)
Discussion started by: ust3
3 Replies

2. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

3. Shell Programming and Scripting

Changing display format

Hi, My file cat a.txt Sat Nov 27 00:02:00 2010 00:02:00 Usr 27: Login by edi on batch. (452) 00:02:09 Usr 27: Logout by on batch. (453) 00:02:09 Usr 27: Login by edi on batch. (452) 00:02:22 Usr 27: Logout by on batch. (453) 00:02:22 Usr 27: Login by edi on batch.... (3 Replies)
Discussion started by: ganeshanbu
3 Replies

4. UNIX for Dummies Questions & Answers

How do i set time in 24 hour format?

Currently whenever i run date command output is shown like Mon Apr 12 05:17:21 IST 2010 When its 17:17 Here. How would i change it so that it should show. Mon Apr 12 17:17:21 IST 2010 (8 Replies)
Discussion started by: pinga123
8 Replies

5. UNIX for Dummies Questions & Answers

Date format Display Help

I have tried various arguments to get the date display as "Mar 10". I have tried date +"%c" -------> Wed Mar 10 11:51:21 EST 2010 date +"%b%d%Y_%H%M%S" --------> Mar102010_115121 date +"%b%d" -------> Mar10 date +"%t%b%e" ... (3 Replies)
Discussion started by: moveaix
3 Replies

6. UNIX for Dummies Questions & Answers

Date Display Format

Hello People, How can I display the date in a continuous format along with the time as below : 20091001_154547 i.e yyyymmdd_hhmmss format. Thanks. (3 Replies)
Discussion started by: sushant172
3 Replies

7. UNIX for Advanced & Expert Users

ls -l timestamp display format

The time stamp format using "ls -l" is either mmm dd hh:mm or mmm dd yyyy. For later case, how can I know the hh:mm as well. Thanks. (3 Replies)
Discussion started by: pok.fung
3 Replies

8. Shell Programming and Scripting

ls command format display

Hi I have 3 files $ ls -l -rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 SANITY_TEST -rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333 -rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333 (1) I need to see this "SANITY_TEST" "Success 123333" "Success... (6 Replies)
Discussion started by: mnmonu
6 Replies

9. Shell Programming and Scripting

display the files in a folder which are older than 1 hour

Hi, I have some files in a folder with different time stamps and I want to display the files which are older than 1 hour. i tried with find. need urgent help. (7 Replies)
Discussion started by: vgs
7 Replies

10. UNIX for Dummies Questions & Answers

display the files in a folder which are older than 1 hour

Hi, I have some files in a folder with different time stamps and I want to display the files which are older than 1 hour. i tried with find. need urgent help. (3 Replies)
Discussion started by: vgs
3 Replies
Login or Register to Ask a Question