To read timestamp and count from a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To read timestamp and count from a line
# 1  
Old 05-12-2013
To read timestamp and count from a line

I have file like:
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


And i want to read the Timestamp from first line and count from the last line.

please help me out
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 05-12-2013 at 12:24 PM.. Reason: code tags, please!
# 2  
Old 05-12-2013
Code:
$ awk 'NR==1{T=$(NF-2)" "$(NF-1)}END{print T,$NF}' file
2013-05-11 12:23:12 000005

# 3  
Old 05-12-2013
Code:
sed -n '/^Date\|^Number/p' file

# 4  
Old 05-12-2013
Code:
$ sed -n -e "s/Date and Time: \(.*\) MST/\1/p" -e "s/Number of Records: *//p" input
2013-05-11 12:23:12
000005

This User Gave Thanks to hanson44 For This Post:
# 5  
Old 05-16-2013
I have to read only the date from the first line. => 2013-05-11

Please help me out
# 6  
Old 05-16-2013
Code:
awk 'NR==1 {f=$4} {l=$NF} END {print f,l}' input
2013-05-11 000005

# 7  
Old 05-16-2013
A variation of Hanson44's solution:
Code:
sed -n 's/Date and Time: \(.*\) \(.*\) .../\1/p;s/Number of Records: *//p' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count the pipes "|" in line and delete line if count greter then number.

Hello, I have been working on Awk/sed one liner which counts the number of occurrences of '|' in pipe separated lines of file and delete the line from files if count exceeds "17". i.e need to get records having exact 17 pipe separated fields(no more or less) currently i have below : awk... (1 Reply)
Discussion started by: ketanraut
1 Replies

2. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

3. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

4. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

5. Shell Programming and Scripting

How to read and write last modified timestamp to files?

Need help reading file last modified date in format: Filename (relative path);YYYYMMDDHHMMSS And then write it back. My idea is to backup it to a text file to restore later. Checked this command but does not work: Getting the Last Modification Timestamp of a File with Stat $ stat -f... (5 Replies)
Discussion started by: Tribe
5 Replies

6. Shell Programming and Scripting

To read timestamp from a line

I have a situation like, I have to read only the timestamp value from a line. ex: Date and Time : 2013-05-11 12:12:34 MST I cut the 'Date and Time' but unable to remove MST part. I need a script to use in Datastage job. can you guys help me with that Thanks in advance (2 Replies)
Discussion started by: Abhisrajput
2 Replies

7. Shell Programming and Scripting

Read directories sequential based on timestamp

Hi, I have a directory structure like below Directoryname create time d1 12:00 d2 12:05 d3 12:08 I want to read the directories based on timestamp.That is oldest directory must be read first and kick off certain process. ... (7 Replies)
Discussion started by: chetan.c
7 Replies

8. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

9. Shell Programming and Scripting

Shell script to count number of ~ from each line and compare with next line

Hi, I have created one shell script in which it will count number of "~" tilda charactors from each line of the file.But the problem is that i need to count each line count individually, that means. if line one contains 14 "~"s and line two contains 15 "~"s then it should give an error msg.each... (3 Replies)
Discussion started by: Ganesh Khandare
3 Replies

10. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies
Login or Register to Ask a Question