File processing


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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

# 3  
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  
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  
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  
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  
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
Login or Register to Reply

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

More UNIX and Linux Forum Topics You Might Find Helpful
awk processing / Shell Script Processing to remove columns text file
ajayram
Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M...... Programming
5
Programming
How to make parallel processing rather than serial processing ??
Samb95
Hello everybody, I have a little problem with one of my program. I made a plugin for collectd (a stats collector for my servers) but I have a problem to make it run in parallel. My program gathers stats from logs, so it needs to run in background waiting for any new lines added in the log...... Shell Programming and Scripting
0
Shell Programming and Scripting
how to change the current file processing to some other random file in awk ?
salman4u
Hello, say suppose i am processing an file emp.dat the field of which are deptno empno empname etc now say suppose i want to change the file to emp.lst then how can i do it? Here i what i attempted but in vain BEGIN{ system("sort emp.dat > emp.lst") FILENAME="emp.lst" } { print...... Shell Programming and Scripting
2
Shell Programming and Scripting
Have a shell script check for a file to exist before processing another file
heprox
I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still...... Shell Programming and Scripting
3
Shell Programming and Scripting