Script To read Date and count from files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script To read Date and count from files
# 1  
Old 05-19-2013
Script To read Date and count from files

Smaple 1

Code:
Date and Time: 2013-05-11 12:23:12 MST
abc,1234,hi-all,45354-88888,IN,US
XYZ,1234,hi-all,45354-88888,OUT,GB
abc,1234,hi-all,45354-88888,IN,AS
abc,1234,hi-all,45354-88888,OUT,US
abc,1234,hi-all,45354-88888,IN,US
Number of Records: 000005

Sample 2

Code:
HDR: 20130511
abc,1234,hi-all,45354-88888,IN,US
XYZ,1234,hi-all,45354-88888,OUT,GB
abc,1234,hi-all,45354-88888,IN,AS
abc,1234,hi-all,45354-88888,OUT,US
abc,1234,hi-all,45354-88888,IN,US
TRL: 000005

Let suppose if I have these two formats of file. And need two get only date from the first line and the counts of record from the last line. And in sample 2 the date format should be 2013-05-11. I can get any of the file.
Can some help me with a shell script for this. I will be highly thank full.

Last edited by Scrutinizer; 05-19-2013 at 06:03 AM.. Reason: icode tags to code tags
# 2  
Old 05-19-2013
Quote:
Originally Posted by Abhisrajput
need two get only date from the first line and the counts of record from the last line.
Code:
$ awk '/Date and Time/{print $4,$5}/Number of Records/{print $NF}' file1
2013-05-11 12:23:12
000005

Quote:
Originally Posted by Abhisrajput
the date format should be 2013-05-11.
Code:
$ awk '/HDR/{$2=substr($2,1,4) "-" substr($2,5,2) "-" substr($2,7)}1' file2
HDR: 2013-05-11
abc,1234,hi-all,45354-88888,IN,US
XYZ,1234,hi-all,45354-88888,OUT,GB
abc,1234,hi-all,45354-88888,IN,AS
abc,1234,hi-all,45354-88888,OUT,US
abc,1234,hi-all,45354-88888,IN,US
TRL: 000005

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to count matched string then check again from last read position

Hi all, I am currently trying to figure out how can i capture a particular string from a log file, then search again but from the last line it read before onward. Basically let's say that the check runs every 5 mins via cron, counting the number of matched strings "Cannot assign requested... (5 Replies)
Discussion started by: nms
5 Replies

2. Shell Programming and Scripting

Extract count of string in all files and display on date wise

Hi All, hope you all are doing well! I kindly ask you for shell scripting help, here is the description: I have huge number of files shown below on date wise, which contains different strings(numbers you can say) including 505001 and 602001. ... (14 Replies)
Discussion started by: VasuKukkapalli
14 Replies

3. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

4. Shell Programming and Scripting

How to read files by Server Creation date wise?

Hi All, I would have many files in the server with xyz*.dat -- Static file name Physical files: xyz1.dat - 01PM xyz2.dat - 02PM xyz3.dat - 03PM In present version we are using for f in $file_name do fname=`ls $f | grep -v ^'\|'$ | sed s/' '/'\\ '/g` .... sqlldr... (4 Replies)
Discussion started by: Dharv
4 Replies

5. Shell Programming and Scripting

How to grep and count the occurences in while read script?

Hi, I have a file while is the output of lspath command and output of file is #cat lspath.txt Enabled hdisk0 vscsi0 Enabled hdisk0 vscsi1 Enabled hdisk1 vscsi0 Enabled hdisk2 vscsi0 Enabled hdisk2 vscsi1 Missing hdisk3 vscsi0 Enabled hdisk3 vscsi1 Have created script to check state... (7 Replies)
Discussion started by: ksgnathan
7 Replies

6. Shell Programming and Scripting

Help with script to read lines from file and count values

Hi, I need some help with a script I'm trying to write. I have a log file containing references to a number of different webservices. I wish to write a script that will list the webservices with a count as to how many times they appear in the log. An example of the log file content: ... (2 Replies)
Discussion started by: gman2010
2 Replies

7. Shell Programming and Scripting

Shell Script to compare files, check current date and count

Hello - I have written the following basic shell script to count files, compare files and look for a particular strings in a file. Problem 1: How do I define more than 1 file location? #!/bin/bash #this is a test script FILES=$(ls /home/student/bin/dir1, home/student/bin/dir2)... (0 Replies)
Discussion started by: DallasT
0 Replies

8. UNIX for Dummies Questions & Answers

Read directory files and count number of lines

Hello, I'm trying to create a BASH file that can read all the files in my working directory and tell me how many words and lines are in that file. I wrote the following code: FILES="*" for f in "$FILES" do echo -e `wc -l -w $f` done My issue is that my file is outputting in one... (4 Replies)
Discussion started by: jl487
4 Replies

9. Shell Programming and Scripting

Delete files older than 3 months.(read date from the name of the file)

Guys, My log files stored in the date format format below(log_20080714072942): TIMESTAMP=`date +%Y%m%d%H%M%S` LOG=/log/log_${TIMESTAMP}.log I'm looking for a shell script which deletes all files which is older than 3 months from today. Regards, Bhagat (3 Replies)
Discussion started by: bhagat.singh-j
3 Replies

10. Shell Programming and Scripting

Count of files based on date?

Hi Friends, Can anyone help me with this: To get the count of files that are existing in a directory created on a perticular date like in the example (01/08) .(having same pattern for the filename) ex: FileName Creted Date FILE001 01/08/2007 FILE005 ... (6 Replies)
Discussion started by: sbasetty
6 Replies
Login or Register to Ask a Question