Help with Grep Specific Date From One File Into A New One

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Help with Grep Specific Date From One File Into A New One
# 1  
Old 02-21-2018
Help with Grep Specific Date From One File Into A New One

Hello All,

First post, don't know much about Linux/Unix, but I need some help. Normally, I do grep 'what I'm searching for' FILE > file.txt so I can pull data from one file, and put it into a new one. The issue I am having is with specific dates, since the date field is 4, and it appears elsewhere in the header, it's pulling more dates than what I need/want. I just want specific date (yyyymmdd format) from one file to be put into another file. Most of the command with awk/sed I have seen (I am still not too familiar with these) are just listing, when I need this in a whole new file.

Thanks in advanced for the help!
# 2  
Old 02-21-2018
Welcome to the forum.

Please be way more specific, supplying sample data containing good and bad examples, if you want more than just generic statements like "Use adequate regex".
# 3  
Old 02-21-2018
Quote:
Originally Posted by RudiC
Welcome to the forum.

Please be way more specific, supplying sample data containing good and bad examples, if you want more than just generic statements like "Use adequate regex".
My manager was able to help me out on this (was in a meeting) so here was what worked:

Code:
cat FILE | awk -F\| '$4~/^20180202$/' >> fundfile.txt

Thanks, all. This can be closed.

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-21-2018 at 09:35 AM.. Reason: Added CODE tags.
# 4  
Old 02-21-2018
Quote:
Originally Posted by DennisG34
Code:
cat FILE | awk -F\| '$4~/^20180202$/' >> fundfile.txt

AWK can read a file without the need of cat and it appears that there is no need of a regular expression if you know that the fourth field may only contain the number 20180202

Code:
awk -F\| '$4 == "20180202"' FILE

That will filter every line of FILE, displaying to screen only those that match.
If you want to save the result in a file fundfile.txt and this file doesn't exist or exist but you want to rewrite it, then you can redirect to it

Code:
awk -F\| '$4 == "20180202"' FILE > fundfile.txt

If the file fundfile.txt exist and you do not want to override its content, then you append to it.

Code:
awk -F\| '$4 == "20180202"' FILE >> fundfile.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

2. Shell Programming and Scripting

Grep a log file starting from a specific time to the end of file

I have a log file which have a date and time at the start of every line. I need to search the log file starting from a specific time to the end of file. For example: Starting point: July 29 2018 21:00:00 End point : end of file My concern is what if the pattern of `July 29 2018 21:00:00`... (3 Replies)
Discussion started by: erin00
3 Replies

3. Shell Programming and Scripting

How to print the specific part of the file name with file creation date?

Hello Folks, I have an requirement, where i need to get total count of the file based on creation date with there filename selected pattern. Filename: MobileProtocol.20171228T154200.157115.udr I want to get the count of files created on each day based on a pattern find. find . -type... (7 Replies)
Discussion started by: sadique.manzar
7 Replies

4. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

5. Shell Programming and Scripting

Grep all lines for a specific date in log-files

I need to grep all lines for "yesterday" in /var/log/messages. Dates are in the format "YYYY-MM-DD". (5 Replies)
Discussion started by: Padmanabhan
5 Replies

6. Shell Programming and Scripting

Delete file with specific date

let say i have list of file PermissionsDirectoriesGroupSizeDateDirectory or file drwx------2users4096Nov 2 19:51mailv drwxr-s---35www 32768Jan 20 22:39public_htmlt drwx------ 2 users 4096 Nov 2 19:51 mail drwxr-s--- 35 www 32768 Jan 20 22:39 public_html drwxr-s--- 35 www 32768 Jan... (3 Replies)
Discussion started by: Jewel
3 Replies

7. Shell Programming and Scripting

how to filter file for specific date

Hi My OS is solaris 64 bit 10, I have many files in a logs directory where we recive 40-50 logs every day. i have last 20 days file present in this directory. I want to move each day file to a particulaar directory whose name is appended with the date of file. eg Code: 1.txt file... (1 Reply)
Discussion started by: guddu_12
1 Replies

8. Shell Programming and Scripting

Grep only specific lines ordered by column/date

Hi everybody, I'd like to think I've been through the search tool not only on this site, but also on google too, but I haven't been able to find what I was looking for. If I might've missed something on this forum, please slap me in the face with a link that you consider useful for my query :D ... (4 Replies)
Discussion started by: dilibau
4 Replies

9. Shell Programming and Scripting

grep and cat based on specific mod date

I'm trying to figure out how to open and copy all contents of files last modded on aug 14 to one single text file. Also, I'm trying to do this in one command string. I have ls -l -R | grep "Aug 1" but all this does is print the -l info with Aug 1 in it. how can I modify this so that ls... (3 Replies)
Discussion started by: mmixology
3 Replies

10. Shell Programming and Scripting

grep a specific line from a file

Is there a way to grep only one line from a file listing name of files? If I use head -1 it's ok(the first line only) If I use head -2 it's not good because I have already checked the first line. I'd like something like this: while test $i -le $max do grep "$3" `head -$i temp.txt` >... (4 Replies)
Discussion started by: Max89
4 Replies
Login or Register to Ask a Question