running Mac OS X version 10.6.8
using case makes sense. i'll try it and let you know what happens.
thank you!
---------- Post updated at 11:31 AM ---------- Previous update was at 11:08 AM ----------
Code:
$ cat date_configurator.sh
#!/bin/bash -x
while read DATE TIME REST
do
case "$DATE $TIME" in
200[3-4]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])
# format $DATE $TIME into epoch time
BAD_DATE=`date -j -f "%Y-%m-%d %H:%M:%S" "${DATE} ${TIME}" "+%s"`
# add 246471660 seconds to $BAD_DATE
ADJ_DATE=`expr ${BAD_DATE} + 246471660`
# re-format $ADJ_DATE back to original format of $DATE $TIME
FIXED_DATE=`date -j -f "%s" "${ADJ_DATE}" "+%Y-%m-%d %H:%M:%S"`
# replace $DATE $TIME with $FIXED_DATE
sed "s/${DATE}/${FIXED_DATE}/"
;;
*) # Do nothing
;;
esac
echo "$DATE $TIME $REST"
done < test.txt > test2.txt
$ ./date_configurator.sh
./date_configurator.sh: line 6: syntax error near unexpected token `[0-9][0-9]:[0-9][0-9]:[0-9][0-9]'
./date_configurator.sh: line 6: ` 200[3-4]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])'
---------- Post updated at 03:41 PM ---------- Previous update was at 11:31 AM ----------
after much research and toil and with Corona688's insight, i have a working script.
Code:
#!/bin/bash
echo "Enter file name that contains corrupt dates and press [ENTER]"
read file_name
output=`echo "$file_name"_edited`
while read DATE TIME REST
do
if [[ "$DATE" =~ 200[3-4]-[0-9][0-9]-[0-9][0-9] ]]
then
BAD_DATE=`date -j -f "%Y-%m-%d %H:%M:%S" "${DATE} ${TIME}" "+%s"`
ADJUSTED_DATE=`expr ${BAD_DATE} + 246471660`
FIXED_DATE=`date -j -f "%s" "${ADJUSTED_DATE}" "+%Y-%m-%d %H:%M:%S"`
echo "$FIXED_DATE $REST" >> $output
else
echo "$DATE $TIME $REST" >> $output
fi
done < $file_name
I've seen several examples of grep showing the filename the string was found in, but what I really need is grep to show the file details in long format (like ls -l would).
scenario is:
grep mobile_number todays_files
This will show me the string I'm after & which files they turn up in, but... (2 Replies)
Hello
i have go the following result from performing 2 testing using the same file.
I have used unix script to extract the result because the files are many as shown below.
01_gravity.f.tcov 7 3 42.86
02_gravity.f.tcov 9 4 80.86... (4 Replies)
Hey everyone,
Basically, all I'm looking for is a way to regex for not a certain string. The regex I'm looking to avoid matching is:
D222
i.e. an equivalent of:
awk '!/D222/'
The problem is that I use this in the following command in a Bash script:
ls ${source_directory} | awk... (1 Reply)
Here is the sample of my file address.txt
Address 1
1234 Drive way
New Orleans, LA
Zipcode :- 12345
Address 2
4567 Spring way
Chicago, IL
Zipcode :- 67890
I would like to grep for an Address title (Ex :- Address 2) , then get its zipcode and echo both in a single line. Ex :- ... (3 Replies)
I am trying to match a pattern exactly in a shell script. I have tried two methods
awk '/\<mpath${CURR_MP}\>/{print $1 $2}' multipath
perl -ne '/\bmpath${CURR_MP}\b/ and print' /var/tmp/multipath
Both these methods require that I use the escape character. I am guessing that is why... (8 Replies)
I have a file that contains the 2 following lines (from /proc/mounts)
/dev/sdc1 /mnt/backup2 xfs rw,relatime,attr2,noquota 0 0
/dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0
I need to match the string in the second column exactly so that only one result is returned, e.g.
> grep... (2 Replies)
I want to know the processing time taken by a node.example suppose a node ges a rreq...then it searched through it's table to see if it has a fresh route or not.I want to know this search time...is their any function available for doing this in ns2 or in glomosim.Any help is highly appreciated ... (1 Reply)
Hi
Not sure if this can be achieved by unix , but still would like to know if there is any way by which I can do the below given logic
cat sam1 > out1
cat sam2 > out2
when either one of this finished the the next file shd be written in that file, meaning
cat sam3 >> out1/out2... (2 Replies)
I need to fetch particular string from log file based on grep condition match.
Actual requirement is need to print the next word from the same line based on grep string condtion match.
File :Java.lanag.xyz......File copied completed : abc.txt
Ouput :abc.txt
I have used below... (5 Replies)
Hello,
one step in a shell script i am writing, involves Grep command to search a regular expression in a line an only print the string after the match
an example line is below
/logs/GRAS/LGT/applogs/lgt-2016-08-24/2016-08-24.8.log.zip:2016-08-24 19:12:48,602 ERROR... (9 Replies)
Discussion started by: Ramneekgupta91
9 Replies
LEARN ABOUT OSX
time2posix
TIME2POSIX(3) BSD Library Functions Manual TIME2POSIX(3)NAME
time2posix, posix2time -- convert seconds since the Epoch
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <time.h>
time_t
time2posix(time_t t);
time_t
posix2time(time_t t);
DESCRIPTION
IEEE Std 1003.1-1988 (``POSIX.1'') legislates that a time_t value of 536457599 shall correspond to "Wed Dec 31 23:59:59 GMT 1986." This
effectively implies that POSIX time_t's cannot include leap seconds and, therefore, that the system time must be adjusted as each leap
occurs.
If the time package is configured with leap-second support enabled, however, no such adjustment is needed and time_t values continue to
increase over leap events (as a true `seconds since...' value). This means that these values will differ from those required by POSIX by the
net number of leap seconds inserted since the Epoch.
Typically this is not a problem as the type time_t is intended to be (mostly) opaque--time_t values should only be obtained-from and passed-
to functions such as time(3), localtime(3), mktime(3) and difftime(3). However, IEEE Std 1003.1-1988 (``POSIX.1'') gives an arithmetic
expression for directly computing a time_t value from a given date/time, and the same relationship is assumed by some (usually older) appli-
cations. Any programs creating/dissecting time_t's using such a relationship will typically not handle intervals over leap seconds cor-
rectly.
The time2posix() and posix2time() functions are provided to address this time_t mismatch by converting between local time_t values and their
POSIX equivalents. This is done by accounting for the number of time-base changes that would have taken place on a POSIX system as leap sec-
onds were inserted or deleted. These converted values can then be used in lieu of correcting the older applications, or when communicating
with POSIX-compliant systems.
The time2posix() function is single-valued. That is, every local time_t corresponds to a single POSIX time_t. The posix2time() function is
less well-behaved: for a positive leap second hit the result is not unique, and for a negative leap second hit the corresponding POSIX time_t
does not exist so an adjacent value is returned. Both of these are good indicators of the inferiority of the POSIX representation.
The following table summarizes the relationship between time_t and its conversion to, and back from, the POSIX representation over the leap
second inserted at the end of June, 1993.
DATE TIME T X=time2posix(T) posix2time(X)
93/06/30 23:59:59 A+0 B+0 A+0
93/06/30 23:59:60 A+1 B+1 A+1 or A+2
93/07/01 00:00:00 A+2 B+1 A+1 or A+2
93/07/01 00:00:01 A+3 B+2 A+3
A leap second deletion would look like...
DATE TIME T X=time2posix(T) posix2time(X)
??/06/30 23:59:58 A+0 B+0 A+0
??/07/01 00:00:00 A+1 B+2 A+1
??/07/01 00:00:01 A+2 B+3 A+2
[Note: posix2time(B+1) => A+0 or A+1]
If leap-second support is not enabled, local time_t's and POSIX time_t's are equivalent, and both time2posix() and posix2time() degenerate to
the identity function.
SEE ALSO difftime(3), localtime(3), mktime(3), time(3)BSD September 11, 2005 BSD