File processing

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 03-07-2014
File processing

Hi,

I have a file
Code:
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:
Code:
2013-01-01
2013-01-02

File 2:
Code:
01-03-2013
03-03-2013
mar05

# 2  
Old 03-07-2014
Ok. Where are you stuck with your script?

--ahamed
# 3  
Old 03-08-2014
I used
Code:
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
# 4  
Old 03-08-2014
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
# 5  
Old 03-08-2014
I used
test.txt
Code:
2013-01-01
2013-03-03
mar94
99-39034
03-40-2930

Code:
--> 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

Code:
--> 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
# 6  
Old 03-08-2014
For the second output, use both -E and -v option.
Code:
 grep -Ev '[0-9]{4}-[0-9]{2}-[0-9]{2}' test.txt

Code:
 man grep
        -v, --invert-match
              Invert the sense of matching, to select non-matching lines.  (-v is specified by POSIX.)

--ahamed
# 7  
Old 03-08-2014
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

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
File Processing nikhil jain Shell Programming and Scripting 3 03-29-2017 04:37 AM
awk - Rename output file, after processing, same as input file High-T UNIX for Dummies Questions & Answers 12 02-01-2015 09:34 PM
awk processing / Shell Script Processing to remove columns text file ajayram Programming 5 03-23-2013 02:51 PM
Recursive file processing from a path and printing output in a file Optimus81 Shell Programming and Scripting 1 12-14-2012 12:55 PM
Help with File processing karumudi7 Shell Programming and Scripting 7 10-10-2011 04:34 PM
File Processing expert Shell Programming and Scripting 2 05-07-2011 01:42 AM
Help in file processing selvam Shell Programming and Scripting 6 04-16-2011 11:25 PM
How to make parallel processing rather than serial processing ?? Samb95 Shell Programming and Scripting 0 08-16-2010 04:56 AM
help with processing a file dsravan Shell Programming and Scripting 4 06-16-2010 02:22 PM
How to processing the log file within certain dates based on the file name shyork2001 Shell Programming and Scripting 1 04-09-2010 11:58 AM
File processing siba.s.nayak UNIX for Dummies Questions & Answers 2 11-25-2009 10:05 AM
how to change the current file processing to some other random file in awk ? salman4u Shell Programming and Scripting 2 03-02-2009 04:35 AM
Checking for a control file before processing a data file purna.cherukuri Shell Programming and Scripting 4 09-01-2008 11:52 AM
Have a shell script check for a file to exist before processing another file heprox Shell Programming and Scripting 3 11-14-2006 03:26 AM