"awk date" help please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "awk date" help please
# 1  
Old 10-08-2012
"awk date" help please

first of all i must say i am new in shell, awk programming, so this question may be so easy but i didn't do it.

i have a list like above;
Code:
Sep06 10:03 C 
Sep06 10:05 C  
Oct04 16:52 SM 
Jun03 22:56 S  
Jul17 15:57 S 
Aug03 12:19 S  
Aug03 12:23 S
Jul03 14:05 S

i want to get second(%s) values of dates(Sep06,Oct04 vb.), hours is not important. I got this list by ecsinfo command. All information is not in this list but this is what i interested in. The code i have written :
Code:
`/opt/Opentext/Exceed_Connection_Server_13.7_64/bin/./ecsinfo | awk '
{
        i=$3;
        if ( i == "S") {
 
                j=$1;
                i="date +%b%d"
                
                "date -d i +%s" | getline k
                print k

                "date -d j +%s" | getline c
                print c
        
        }
}'`

------------------------------------------
Code:
"date -d i +%s" | getline k
print k

this first part prints the second value of system date, but in second part(above)
Code:
"date -d j +%s" | getline c
print c

i got this error. 

date: invalid date `j'

i dont know why, i need help for this.

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by vbe; 10-09-2012 at 04:53 AM..
# 2  
Old 10-08-2012
Change your command to the following:
Code:
$(/opt/Opentext/Exceed_Connection_Server_13.7_64/bin/./ecsinfo|awk '$3 == "S"{
p="date -d " $1 " +%s"
p | getline c
close(p)
print today
print c
}' today="$(date -d '00:00:00' +%s)")

# 3  
Old 10-09-2012
it works, thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk variable into shell command "date -d": possible...?

Hello, there! I am trying to pass an awk variable into a shell command in order to collect the result into an awk variable; in Bash it does work, as in: v='2'; date -d "now + $v weeks" But in awk it does not, as in: v="2" "date -d 'now + v weeks'" | getline newdate close ("date -d 'now... (3 Replies)
Discussion started by: fbird3
3 Replies

2. Shell Programming and Scripting

awk "date" and "system" command

Hello experts! I need your help please I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.: 2016-11-25 03:14:50and pass them to "date" command, but also append the 9th column in a file as well. So I want to execute date -d '2016-11-25 03:14:50' ... (2 Replies)
Discussion started by: phaethon
2 Replies

3. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

4. Shell Programming and Scripting

Using external "date" command from awk

For some dumb reason, I'm having the strangest hard time getting awk to convert epoch time to UTC human time. I'm using CentOS 5.5 and gawk 3.1.5. There are 2 approaches that I know. First, the strftime call: Tandy400 $ echo 1308607169 | awk '{print strftime("%c",$1)}' Mon 20 Jun 2011... (3 Replies)
Discussion started by: treesloth
3 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

7. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

8. Shell Programming and Scripting

help for saving vertical datas to horizontal with "awk" or "cut"

hi, i have a file having datas like that ./a.txt 12344 12345 12346 12347 ..... ..... ... i want to save this datas to another file like that ./b.txt 12344 12345 12346 12347 ... ... ... i think awk can make this but how? :) waiting for ur help. (3 Replies)
Discussion started by: mercury
3 Replies

9. UNIX for Advanced & Expert Users

add seconds to: date"|"time"|"HHMMSS

Hey all, I have a shell that invokes a AWK. In this AWK i want invoke a function that receives 3 parameters: date: 20080831 time: 235901 duration: 00023 that function receive this 3 parameters and sum to this value two more seconds: 2008083123590100025 Remember that in case that... (3 Replies)
Discussion started by: anaconga
3 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question