LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-10-2013, 03:01 PM   #1
jdgr
Member
 
Registered: Feb 2012
Location: Ontario, Canada
Distribution: Fedora 18
Posts: 65

Rep: Reputation: Disabled
Command line search in file for < date


Hi All,

I have a csv file that I am trying to parse through looking for any lines that are less than a today's date.

I've been trying to use grep, but it doesn't seem to work for "less than". I saw on a few sites I could use
Code:
awl '$7 <= date' file.csv
but it doesn't seem to work.

Does anyone know how to search through a file to find everything before today's date.

I'm running Fedora 18.

Thanks,
Jeremy
 
Old 04-10-2013, 03:18 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
the name of the command should be awk
 
Old 04-10-2013, 03:42 PM   #3
jdgr
Member
 
Registered: Feb 2012
Location: Ontario, Canada
Distribution: Fedora 18
Posts: 65

Original Poster
Rep: Reputation: Disabled
Sorry, that was a typo when I submitted. Doing two things at once. I was running the command
Code:
awk '$7 <= date' file.csv
and it doesn't work like it should. I even converted the dates into their integer equivalents and tried searching for less than the number, and that still didn't return the correct results.

Thanks,
Jeremy
 
Old 04-10-2013, 04:44 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Maybe posting some sample lines from file.csv and the incorrect output of your awk command would help people narrow it down.
 
1 members found this post helpful.
Old 04-11-2013, 08:00 AM   #5
jdgr
Member
 
Registered: Feb 2012
Location: Ontario, Canada
Distribution: Fedora 18
Posts: 65

Original Poster
Rep: Reputation: Disabled
Here are the first couple lines of my csv file
Code:
Employee,Phone Model,Number,Provider,,Personal/Company,Eligible for Hardware Upgrade,Extra Cost,User Response,Model,Serial Number,IMEI/MEID 
Alan Bunting,Blackberry 9660,,,,Company,41012,,Pesonal,Blackberry Torch 9860,2869EE7B,356838.04.186284.1
Allan Pepper,Samsung Galaxy Nexus S,,Rogers,,Company,41459,,,,,
Allan Webb,Blackberry 9860,,,,Company,41725,,,,,
It's a listing of the cell phone users in my company. The seventh column (starting at 1) is the date field. At present, it is set as an integer date (which may also be blank) to try and make things simpler. If I run the command
Code:
awk '$7 <= 41375' cellphones.csv
it dumps out the entire file. It doesn't give any error, just outputs the entire file everytime, as if it's matching every line (which is not possible).

Thanks,
Jeremy
 
Old 04-11-2013, 08:17 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
man awk
[schneidz@hyper ~]$ awk -F , '$7 <= 41375' jdgr.csv 
Alan Bunting,Blackberry 9660,,,,Company,41012,,Pesonal,Blackberry Torch 9860,2869EE7B,356838.04.186284.1
fyi: this looks cleaner:
Code:
awk -F , '$7 <= 20130101' jdgr.csv

Last edited by schneidz; 04-11-2013 at 08:25 AM.
 
Old 04-11-2013, 08:35 AM   #7
jdgr
Member
 
Registered: Feb 2012
Location: Ontario, Canada
Distribution: Fedora 18
Posts: 65

Original Poster
Rep: Reputation: Disabled
I have never used awk before and I was originally trying to do it with grep. The commands I found online didn't include the -F option, and while I looked through man awk, I missed that option because I didn't know what I was looking for (I thought the $7 was the problem).

Thanks very much for your help, the command worked like I wanted. Now that I have the proper syntax, I will be changing it back over to date format.

Thanks again!
Jeremy
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
search folders, find a line in a file, and replace it with a new line ithirdeye Programming 2 04-07-2012 04:27 PM
showing date on command prompt line? gangsta77 Linux - General 3 03-02-2011 11:15 AM
multiple pattern search in a single file line by line saheervc Linux - Newbie 2 09-01-2010 11:45 PM
How to search for a file that has the date in the filename nomenclature iherrejon Linux - Newbie 7 11-07-2008 12:26 AM
Syntax for setting up the date via Command line. Lespuff Linux - Newbie 1 11-20-2003 07:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration