Is there a way to retrieve the date (02/09/2016), wherever it's located in the line?
I'm writing a script that checks Carbon Copy Cloner backups.
This was my first step which returns details of the last backup:
Which outputs
I've tried this for testing purposes: Sample input
Although this works on my machine, I've tested this on other machines and it's not very efficient because the date is in a different place.
Expected output
Can this be done?
Last edited by rbatte1; 09-07-2016 at 12:42 PM..
Reason: Added CODE tags for expected output, just to be sure
As a general remark: "a date" is not a standardised (or standardisable) data format. You can search (as RudiC suggested) for this regex, but be aware that it doesn't search for "a date" but for two digits, followed by a slash, followed by two more digits, followed by another slash, followed by four more digits.
In most cases, a string matching that will be a date indeed, but it might be something else either. Further more, this: 1/1/2016 is perhaps a date too, but wouldn't be found by the regex. On the other hand you could remove the restrictions RudiC has perhaps put in for safety and simplify the regexp to:
but in this case it would find a "date" in the following sample text, which denotes the common way in Austria to tell the street number, apartment number and the floor on which it is located:
Bottom line is: you will have to be careful to watch if what you place as restrictions to dates will lead to all the correct things being found and all the incorrect ones being thrown out. But this is a slippery slope and there is no final algorithm which separates all "dates" from everything "not a date".
I have a test file with the following format, It contains the username_date when the user was locked from the database.
$ cat lockedusers.txt
TEST1_21062016
TEST2_02122015
TEST3_01032016
TEST4_01042016
I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Sed command to replace a line in a file using line number from the output of a pipe.
Is it possible to replace a whole line piped from someother command into a file at paritcular line...
here is some basic execution flow..
the line number is 412
lineNo=412
Now i have a line... (1 Reply)
Hello,
I have a file like this:
2012112920121130
12345620121130msABowwiqiq
34477420121129amABamauee
e7748420121130ehABeheheei
in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Hi Guys,
I have a file with following content
From 20121014 : To 20121014
Number of days : 1
1234
1245
1246
1111
Everyday i run my script i want to modify "To" date on the first line with current date. I have set the current date in script as
RUN_DATE=`date -u +%Y%m%d`
So i want... (9 Replies)
Hello,
I was wondering if anyone knows a faster way to search and compare strings and dates from 2 files?
I'm currently using "for loop" but seems sluggish as i have to cycle through 10 directories with 10 files each containing thousands of lines.
Given:
-10 directories
-10 files... (4 Replies)
Hi Guys,
Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this:
Command was launched from partition 0.
------------------------------------------------
Executing command in server server6
Fri Dec 16... (7 Replies)
So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated.
Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Hi Guys,
I am trying to convert a file which has a row based output to a column based output. My original file looks like this:
1
2
3
4
5
6
1
2
3
1
2
3 (8 Replies)
how to make a line BLINKING in output and also how to increase font size in output
suppose in run a.sh script
inside echo "hello world "
i want that this should blink in the output and also
the font size of hello world should be big ..
could you please help me out in this (3 Replies)