Hi,
I have a file
2013-01-01
2013-01-02
01-03-2013
03-03-2013
mar05
I need all the dates YYYY-MM-DD in a separate file and rest of the things in different file.
File 1:
2013-01-01
2013-01-02
File 2:
01-03-2013
03-03-2013
mar05
Hi,
I have a file
2013-01-01
2013-01-02
01-03-2013
03-03-2013
mar05
I need all the dates YYYY-MM-DD in a separate file and rest of the things in different file.
File 1:
2013-01-01
2013-01-02
File 2:
01-03-2013
03-03-2013
mar05
Ok. Where are you stuck with your script?
--ahamed
I used
grep -E '[0-9]{4}-[0-9]{2}-[0-9]{2}' test.txt
could get the first output file.
but I am not sure whether the second is date or month. I need exactly the month ie YYYY-MM-DD format to first file.
I am not sure on how to get the second output file
Good!!
Now use -v along with your grep command to get the second output.
Do read the man page to understand what -v does.
--ahamed
I used
test.txt
2013-01-01
2013-03-03
mar94
99-39034
03-40-2930
--> grep -v '[0-9]{4}-[0-9]{2}-[0-9]{2}' test.txt
2013-01-01
2013-03-03
mar94
99-39034
03-40-2930
--> grep -E '[0-9]{4}-[0-9]{2}-[0-9]{2}' test.txt
2013-01-01
2013-03-03
can you please let me know where I am going wrong
For the second output, use both -E and -v option.
grep -Ev '[0-9]{4}-[0-9]{2}-[0-9]{2}' test.txt
man grep
-v, --invert-match
Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)
--ahamed
Thank you
That worked fine for the second file.
I still have one issue left. In the first file I need only YYYY-MM-DD. But since the dates can be YYYY-DD-MM also . I am using [0-9]{2}-[0-9]{2} so either of the pattern can match. But I need only YYYY-MM-DD.
Can you please guide me
I'm afraid this can't be done in a reliable way. Numbers above 12 indicate that this be the DD field, but how would you tell that a line is dealing with 2. Jan or 1. Feb?
Pipe your grep command for the second file into awk. Set the field separator to"-"then '{print $1,$3,$2}'