extract the relevant data files for a quarter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract the relevant data files for a quarter
# 1  
Old 02-13-2009
extract the relevant data files for a quarter

Code:
CTB_KT_OllyotLvos_20081204_164352_200811.txt
CTB_KT_LN_utahfwd_20081204_164352_200811.txt
CTB_KT_LN_utahfwd_Summ_20081204_164352_200811.txt
CTB_KT_PML_astdt_prFr_20081204_210153_200811.txt
CTB_KT_PML_astdt_prOt_20081204_210153_200811.txt
CTB_KT_PML_astdt_Nopr_20081204_210153_200811.txt
CTB_KT_OllyotLvos_20090111_064702_200812.txt
CTB_KT_LN_utahfwd_20090111_064702_200812.txt
CTB_KT_LN_utahfwd_Summ_20090111_064702_200812.txt
CTB_KT_PML_astdt_prFr_20090112_105344_200812.txt
CTB_KT_PML_astdt_prOt_20090112_105344_200812.txt
CTB_KT_PML_astdt_Nopr_20090112_105344_200812.txt
CTB_KT_OllyotLvos_20090205_145545_200901.txt
CTB_KT_LN_utahfwd_20090205_145545_200901.txt
CTB_KT_LN_utahfwd_Summ_20090205_145545_200901.txt
CTB_KT_PML_astdt_prFr_20090206_010203_200901.txt
CTB_KT_PML_astdt_prOt_20090206_010203_200901.txt
CTB_KT_PML_astdt_Nopr_20090206_010203_200901.txt

This is a set of files in test directory.
format of filename: string_yyyymmdd_hhmmss_previousyearmonth.txt. The yyyymmdd has to be used.
The requirement is get all the files which arrived in a given quarter.So if the quarter is 3 then all files which have arrived in Jan Feb Mar.The files date has to be taken from the file nameSo If I run this for 1st quarter then I should get these files out of the above set. the quarter can be calculated for a field $d which is the last day of the quarter.
Code:
CTB_KT_OllyotLvos_20090111_064702_200812.txt
CTB_KT_LN_utahfwd_20090111_064702_200812.txt
CTB_KT_LN_utahfwd_Summ_20090111_064702_200812.txt
CTB_KT_PML_astdt_prFr_20090112_105344_200812.txt
CTB_KT_PML_astdt_prOt_20090112_105344_200812.txt
CTB_KT_PML_astdt_Nopr_20090112_105344_200812.txt
CTB_KT_OllyotLvos_20090205_145545_200901.txt
CTB_KT_LN_utahfwd_20090205_145545_200901.txt
CTB_KT_LN_utahfwd_Summ_20090205_145545_200901.txt
CTB_KT_PML_astdt_prFr_20090206_010203_200901.txt
CTB_KT_PML_astdt_prOt_20090206_010203_200901.txt
CTB_KT_PML_astdt_Nopr_20090206_010203_200901.txt


Last edited by Franklin52; 02-13-2009 at 02:03 PM.. Reason: adding tags
# 2  
Old 02-13-2009
Try this:

Code:
awk -F_ '{
  for(i=1;i<=NF;i++) {
    if(int($i)) {
      q=int(((substr($i,5,2))+2)/3)
      break
    }
  }
}
q==quarter
' quarter=1 datafile

Regards
# 3  
Old 02-13-2009
Pls help in understanding this program.What is the datafile?
# 4  
Old 02-13-2009
Quote:
Originally Posted by w020637
Pls help in understanding this program.What is the datafile?
Replace "datafile" with your filename(s).

Regards
# 5  
Old 02-13-2009
This would return files for first quarter for all the years. I would require that on the basis of end of period ie. if the qtr end date is mar 31 2009 then jan 2009 feb 2009 and mar 2009 should be selected and should not include files from preious year for the same qtr.
Thanks
# 6  
Old 02-13-2009
Its returning all the files. I just require files for that particular qtr.

Thanks
# 7  
Old 02-13-2009
Code:
/bin/ls -l |
  grep '_200090[123].._'

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 extract only relevant part from a sentence?

Hello All, I have a file with details such as below. How do i extract only the host and port ? eg: dbs.ads.com 1521 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbs.ads.com)(PORT=1521))(CONNECT_DATA=(SID=vug)))... (5 Replies)
Discussion started by: JohnJacobChacko
5 Replies

2. Shell Programming and Scripting

Match and extract data using two files

Hello, Using the information in file 1, I would like to extract from file2 all rows which matchs in column 3. file 1 1233 1230 1231 1232 file2 65733.00 19775.00 1220 65733.00 19793.00 1220 65733.00 19801.00 1220 65733.00 19809.00 1231 65733.00 19817.00 ... (2 Replies)
Discussion started by: jiam912
2 Replies

3. UNIX for Dummies Questions & Answers

Extract common data out of multiple files

I am trying to extract common list of Organisms from different files For example I took 3 files and showed expected result. In real I have more than 1000 files. I am aware about the useful use of awk and grep but unaware in depth so need guidance regarding it. I want to use awk/ grep/ cut/... (7 Replies)
Discussion started by: macmath
7 Replies

4. Shell Programming and Scripting

extract data from 2 files

file 1 WASH7P 17232,18267,18500,20564 17368,18362,18554,21139 file 2 chr1 14969 15038 Exon WASH7P chr1 17232 17368 Exon WASH7P chr1 17258 17368 Exon WASH7P chr1 17605 17742 Exon WASH7P chr1 18267 18362 Exon WASH7P chr1 18267 18366 Exon WASH7P... (5 Replies)
Discussion started by: Diya123
5 Replies

5. Shell Programming and Scripting

How to extract information from two files with data range

Hi, I want to make a query about extracting data from two files that both have data ranges. the data that i want to extract; when there is matching between file1 column 2 is equal to file2 column2 , and file1 column 3 and column 4 is within the range of file2 columns 3 and 4. I would like rows... (1 Reply)
Discussion started by: houkto
1 Replies

6. Shell Programming and Scripting

Extract data with awk and write to several files

Hi! I have one file with data that looks like this: 1 data data data data 2 data data data data 3 data data data data . . . 1 data data data data 2 data data data data 3 data data data data . . . I would like to have awk to write each block to a separate file, like this: 1... (3 Replies)
Discussion started by: LinWin
3 Replies

7. Shell Programming and Scripting

extract data with awk from html files

Hello everyone, I'm new to this forum and i am new as a shell scripter. my problem is to have html files in a directory and I would like to extract from these some data that lies between two different lines Here's my situation <td align="default"> oxidizability (mg / l): data_to_extract... (6 Replies)
Discussion started by: sbobotex
6 Replies

8. Shell Programming and Scripting

How to extract data from indexed files (ISAM files) maintained in an unix server.

Hi, Could someone please assist on a quick way of How to extract data from indexed files (ISAM files) maintained in an UNIX(AIX) server.The file data needs to be extracted in flat text file or CSV or excel format . Usually we have programs in microfocus COBOL to extract data, but would like... (2 Replies)
Discussion started by: devina
2 Replies

9. UNIX for Dummies Questions & Answers

AWK, extract data from multiple files

Hi, I'm using AWK to try to extract data from multiple files (*.txt). The script should look for a flag that occurs at a specific position in each file and it should return the data to the right of that flag. I should end up with one line for each file, each containing 3 columns:... (8 Replies)
Discussion started by: Liverpaul09
8 Replies

10. Shell Programming and Scripting

Perl script for extract data from xml files

Hi All, Prepare a perl script for extracting data from xml file. The xml data look like as AC StartTime="1227858839" ID="88" ETime="1227858837" DSTFlag="false" Type="2" Duration="303" /> <AS StartTime="1227858849" SigPairs="119 40 98 15 100 32 128 18 131 23 70 39 123 20 120 27 100 17 136 12... (3 Replies)
Discussion started by: allways4u21
3 Replies
Login or Register to Ask a Question