Remove data from file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove data from file
# 8  
Old 10-02-2013
Exactly 15 days, or older than 15 days?

If it's exactly 15 days (and you have GNU date) you could just do:
grep -v $(date +%m%d%y --date '15 days ago') filelist.txt

For a range you could generate the grep regex:
dates=$(date +%m%d%y)
for i in {1..15}
   dates="${dates}|"$(date +%m%d%y --date "$i days ago")
grep -E "${dates}" filelist.txt > newfilelist.txt

That's bash with GNU date and GNU grep - you may need to fiddle with it if you don't have them.

Last edited by CarloM; 10-02-2013 at 07:32 AM..
# 9  
Old 10-02-2013
If +/- 2 days do not matter:
awk -F '[_.]' 'function mmddyy(x){return (substr(x,1,2)*30+substr(x,3,2)+substr(x,5,2)*365)} mmddyy($2)<mmddyy(date)-15' date=`date +%m%d%y` Filelist.txt

More precise is the previous proposal (calculation in GNU date)
awk -F '[_.]' 'function mmddyy(x){return (substr(x,1,2)*30+substr(x,3,2)+substr(x,5,2)*365)} mmddyy($2)<mmddyy(date)' date=`date --date '15 days ago' +%m%d%y` Filelist.txt

If you think it works for you, redirect the output to a new file with >
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove new line characters from data rows in a Pipe delimited file?

I have a file as below Emp1|FirstName|MiddleName|LastName|Address|Pincode|PhoneNumber 1234|FirstName1|MiddleName2|LastName3| Add1 || ADD2|123|000000000 2345|FirstName2|MiddleName3|LastName4| Add1 || ADD2| 234|000000000 OUTPUT : ... (1 Reply)
Discussion started by: styris
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Please remove sensitive data

Hi Kindly remove the following from the post . These are confidential info posted by mistake please remove the comments section which is first 16 lines in the perl script . Also please remove the ... (1 Reply)
Discussion started by: ptappeta
1 Replies

3. Post Here to Contact Site Administrators and Moderators

Remove sensitive data

Hi Sir, please remove following terms from post as it is sensitive data ifeeds fidedev ironsides feedmgr thanks a lot prabhu (1 Reply)
Discussion started by: ptappeta
1 Replies

4. Shell Programming and Scripting

Remove data from grep command using the pattern in the file

Hi, I writing a shell program to remove the data from output of the find which matches a list in a file I am using the below find command to get the list of files x=`find . -name test*.dat` the output of the find command is as follows test1.dat test2.dat test3.dat test4.dat... (4 Replies)
Discussion started by: pals70423
4 Replies

5. Shell Programming and Scripting

Remove brackets { } in the data

Hello folks, I have a data file in which each line has 54 numbers, and every 3 numbers are bracketed. So totally 18 pairs of brackets in each line. A typical line is like: {29.187000274658203 -16.148000717163086 -0.9380000233650208} {30.63800048828125 -15.977999687194824... (5 Replies)
Discussion started by: rockytodd
5 Replies

6. Shell Programming and Scripting

remove a column of data

Hi my file has two columns: GAII_4:6:100:548:645/1 GTACACAACCCCCCCCCCCCACCCCACCCCCCCCCCCCCC GAII_4:6:100:1:1242/1 AGTCTGCCCCTCCCCCTNNNNNNNTCTTTTNCCTCCTCCT GAII_4:6:100:444:504/1 GTAACACACACCCTGATACTCCCCCCTCCACAACCGCTCT I want to remove the first column and keep only the scond column so it... (1 Reply)
Discussion started by: jdhahbi
1 Replies

7. Shell Programming and Scripting

Remove Headers throughout a data file

I have a data file with over 500,000 records/lines that has the header throughout the file. SEQ_ID Name Start_Date Ins_date Add1 Add2 1 Harris 04/02/08 03/02/08 333 Main Suite 101 2 Smith 02/03/08 01/23/08 287 Jenkins SEQ_ID Name ... (3 Replies)
Discussion started by: psmall
3 Replies

8. Shell Programming and Scripting

Remove unwanted data?

Hi Can any one help me remove the unwanted data? I would want to remove the complete event id 4910 ( the type there is INFO), that means, I have to remove starting from 7th - 19th lines. can any one of you please help? Thanks, (24 Replies)
Discussion started by: hitmansilentass
24 Replies

9. Shell Programming and Scripting

Remove & insertion of data in a same file

I am iterating record by record through a file as below, A,B A,C A,D B,E B,F E,G E,H The same file should look like in the final output as below, A,B B,E E,G E,H B,F A,C A,D (10 Replies)
Discussion started by: videsh77
10 Replies

10. UNIX for Dummies Questions & Answers

Remove Data from Fields

I would like some sugestions on how to solve the following problem with removing selected data from fields. Each day I receive a file containing 22,000 records that I use a combination of awk and the cut command to remove unwanted fields. This is a work in process as I learn more about awk, sed... (4 Replies)
Discussion started by: greengrass
4 Replies
Login or Register to Ask a Question