Hour display format

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Hour display format
# 15  
Old 07-13-2016
The od output clearly shows us that test.sh is not a shell script. Shell scripts are UNIX text files. UNIX text files have a single <newline> character as a line terminator on every line (not the DOS <carriage-return><newline> character pairs as line separators with no line terminator at the end of the file). The <carriage-return> characters in test.sh are extraneous characters at the end of all but the last line in your shell script. They are interpreted as part of the last string on each command line (i.e., as part of a filename operand, as the unknown string then<carriage-return> when the shell keyword then was expected, etc.) and are causing you lots of problems that are sometimes hard to diagnose because the diagnostic messages print the <carriage-return> characters but they frequently are invisible on the screen after they have been printed.

In the shell command language there are single-quotes ('), double-quotes ("), and back-quotes (`). Opening and closing double-quotes (“″) and opening and closing single-quotes (‘') may look nice in pretty-printed text, but they are syntax errors in a shell script.

Yes, you can use ls -t | head -n1 in a shell script and compare the results to the string saved in the variable FILENAME_WANTED by the command:
Code:
FILENAME_WANTED=`date +"HourlyDate_%Y%m%d_%H00.txt"`

but, if instead of the above command you use the command:
Code:
FILENAME_WANTED=`date +"HourlyDate_%Y%m%d_%H00.txt"`<CR>

where <CR> is a visual representation of the <carriage-return> character you have in your current version of test.sh, there will never be a match because the string saved in FILENAME_WANTED contains a trailing <carriage-return> character that is not present in the filename you are reading from ls.

If you want to use notepad instead of learning how to use vi, you must configure it to use UNIX line terminators; not DOS line separators and you must configure it to use shell command language single-quotes (not pretty-printed opening an closing single-quotes), double-quotes (not pretty-printed opening and closing double-quotes), and back-quotes (instead of pretty printed single-quotes) or learn to use the highly preferred $(command) form of command substitution instead of the obsolete `command` form of command substitution and stop using back-quotes in your shell scripts.
# 16  
Old 07-14-2016
Hello Don,

I finally used vi editor and got it working ..

Code:
# Vani Sonti
# 07/14/2016
# find file name match and load data only when a match found 
# if not display msg
#!/usr/bin/sh
FILENAME_WANTED=`date +"HourlyData_%Y%m%d_%H00.txt"`
echo "FILENAME_WANTED = $FILENAME_WANTED"
LIST_OF_FILES=`ls -rt /tmp/v_tst/HourlyData*.txt |tail -1`
echo "LIST_OF_FILES = $LIST_OF_FILES"
echo "------"
if [ "$FILENAME_WANTED" = "$LIST_OF_FILES" ]; then 
echo "matched"
else echo "NotMatched"
fi

output looks this:

Code:
perseus.gasleak(/tmp/v_tst)% sh chk.sh
FILENAME_WANTED = HourlyData_20160714_1200.txt
LIST_OF_FILES = /tmp/v_tst/HourlyData_20160714_1000.txt
------
NotMatched
perseus.gasleak(/tmp/v_tst)%

Everyone, appreciate all your help

Vani

Last edited by V1l1h1; 07-14-2016 at 01:31 PM..
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