Format Time with Awked Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format Time with Awked Output
# 8  
Old 05-31-2010
Awesome! Works like a charm Pseudocoder

Just one annoyance, how do I fix the "READ" portion of the script to jump to the next line for user entry? It'll probably take me some time to figure it out since I'm a noob.


HTML Code:
You must type the date in this format ---> MM-DD-YYY05-27-2010
Code:
#!/bin/bash
read -p "You must type the date in this format ---> MM-DD-YYY" vdate
grep $vdate log.csv |awk -F, '{print $1, $2, $3, $12, $13, $14, $15, $16, $17,$18}' |sed 's/:[0-9][0-9] / /g;s/
.*-[0-9]\{4\} //' |tee /tmp/nm_$vdate.csv

Here's my output:

HTML Code:
23:25 1412 1408 0 0 0 0 1 0 0
23:35 1472 1475 0 0 0 1 0 0 0
23:45 1351 1351 0 0 0 0 0 0 0
23:55 1345 1344 0 0 0 0 0 0 0

Last edited by ravzter; 05-31-2010 at 10:56 AM..
# 9  
Old 05-31-2010
Quote:
Originally Posted by Franklin52
Try:
Code:
#!/bin/bash
echo "You must type the date in this format ---> MM-DD-YYYY"
read vdate

awk -v dat=$vdate '$0 ~ dat{$1="";sub("...$","",$2);sub("^ ","")}1' file

Seems to me to be the best run. No need to feed awk with grep nor to filter output with sed. Alternative to the use of awk sub() function:

Code:
awk -F"[ :]" -v dat=$vdate '$1=="05-25-2010"{print $2":"$3,$5,$6,$7,$8,$9,$10,$11,$12,$13}'

# 10  
Old 05-31-2010
Try this
Code:
echo "You must type the date in this format ---> MM-DD-YYYY" && read -p vdate

Also there is a small typo in your previous postings, it should be 4 Y's I guess Smilie

Last edited by pseudocoder; 05-31-2010 at 10:50 AM..
# 11  
Old 05-31-2010
Quote:
Originally Posted by ripat
Seems to me to be the best run. No need to feed awk with grep nor to filter output with sed. Alternative to the use of awk sub() function:

Code:
awk -F"[ :]" -v dat=$vdate '$1=="05-25-2010"{print $2":"$3,$5,$6,$7,$8,$9,$10,$11,$12,$13}'

I'll give this a shot also! Just need to understand why the date is specific?
I need the script to run daily.

Thanks!

---------- Post updated at 10:02 AM ---------- Previous update was at 09:47 AM ----------

Quote:
Originally Posted by pseudocoder
Try this
Code:
echo "You must type the date in this format ---> MM-DD-YYYY" && read -p vdate

Also there is a small typo in your previous postings, it should be 4 Y's I guess Smilie
Oops! Thanks, and a period to complete the sentence.

BTW It's getting hung with the new READ portion:

Hung Screen
HTML Code:
You must type the date in this format ---> MM-DD-YYYY
vdate05-27-2010
# 12  
Old 05-31-2010
Try without -p switch, like following:
Code:
echo "You must type the date in this format ---> MM-DD-YYYY" && read vdate

If this won't work, please post your current script, maybe there's a typo or something.

Last edited by pseudocoder; 05-31-2010 at 11:22 AM..
This User Gave Thanks to pseudocoder For This Post:
# 13  
Old 05-31-2010
Perfect!

Thank you very much! Just got two more ideas, which I'll try on my own and post results.

Thanks again!

HTML Code:
You must type the date in this format ---> MM-DD-YYYY
05-27-2010
00:05 1282 1278 0 0 0 0 1 4 0
00:15 1094 1091 0 0 0 0 1 0 0
00:25 1030 1031 0 0 0 0 1 0 0
00:35 989 989 0 0 0 0 0 0 0
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate Time diff in milli milliseconds(Time format : HH:MM:SS,NNN)

Hi All, I have one file which contains time for request and response. I want to calculate time difference in milliseconds for each line. This file can contain 10K lines. Sample file with 4 lines. for first line. Request Time: 15:23:45,255 Response Time: 15:23:45,258 Time diff... (6 Replies)
Discussion started by: Raza Ali
6 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

time format

Hello Guys. I have copied the following from the time man pages time -f "%E real,%U user,%S sys" ls -Fs But I am getting -f: command not found Regards (3 Replies)
Discussion started by: fdc2suxs
3 Replies

4. Shell Programming and Scripting

calculate time from a given format

Hi i have a file which consists of the time records in following format H:MM:SS.sss 0:00:09.249 0:00:00.102 0:00:00.105 0:00:08.499 0:00:08.499 0:00:06.980 0:00:04.249 0:00:05.749 0:00:00.108 0:00:00.107 0:00:03.014 0:00:00.000 I need to calculate their equivalent milliseconds... (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

5. Shell Programming and Scripting

Taking 3 greped/awked lines of text

Say I used grep and awk for taking text out of a text file... I now /have 3 lines of text that I want to combine to make 1 line. What command could I use to do this? ... display line 1 twice then sed s/$line1/$line2/ ????... display line 2 twice then sed s/$line2/$line3/ (2 Replies)
Discussion started by: puttster
2 Replies

6. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

7. Shell Programming and Scripting

capturing output from top and format output

Hi all, I'd like to capture the output from the 'top' command to monitor my CPU and Mem utilisation.Currently my command isecho date `top -b -n1 | grep -e Cpu -e Mem` I get the output in 3 separate lines.Tue Feb 24 15:00:03 Cpu(s): 3.4% us, 8.5% sy .. .. Mem: 1011480k total, 226928k used, ....... (4 Replies)
Discussion started by: new2ss
4 Replies

8. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

9. Shell Programming and Scripting

help in time format

how to grep 30 mins from starting time of script let for example,script runs at 02:00am....i want to grep from 01.30 till 02:00 ------------------------------------------------------------------- how to achive this in a k-shell script ? (3 Replies)
Discussion started by: ali560045
3 Replies

10. Shell Programming and Scripting

time format..

HI.. I have some files...when doing "ls -l" its like this.. -rwxr-xr-x 1 e2e e2e 747 Aug 30 15:18 abc.txt how can I get the number YYYYMMDD from this...( since I need to compare this number with some other value..) with the help of date/awk/sed/epoch or whatever u... (1 Reply)
Discussion started by: clx
1 Replies
Login or Register to Ask a Question