Sponsored Content
Top Forums Shell Programming and Scripting Pass awk field to a command line executed within awk Post 302863767 by tuxer on Tuesday 15th of October 2013 05:36:45 AM
Old 10-15-2013
Pass awk field to a command line executed within awk

Hi,

I am trying to pass awk field to a command line executed within awk (need to convert a timestamp into formatted date).
All my attempts failed this far.

Here's an example.
It works fine with timestamp hard-codded into the command
Code:
echo "1381653229 something" |awk 'BEGIN{cmd="date -d @1381653229 +\"%m/%e/%y %H:%M\""; cmd|getline; close(cmd); date=$0;}{print date"|"$2}'

How do I do something like
Code:
echo "1381653229 something" |awk 'BEGIN{cmd="date -d @$1 +\"%m/%e/%y %H:%M\""; cmd|getline; close(cmd); date=$0;}{print date"|"$2}'

Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

can I pass awk variable to system command?

I wanna use a system function to deal with several data. So I use awk variable FILENAME to transfer the file directory to system command, but it does not work. I use a shell function "out_function" to deal with data and save the result in another directory with the same file name. How can I... (2 Replies)
Discussion started by: zhynxn
2 Replies

2. Shell Programming and Scripting

how to pass variable in NR function used in awk command?

Hi I want to pass variables with the NR function in awk command. test_file1 is input file having 500 records. var1=100. var2=200 awk -F" " 'NR >= $var1 && NR <= $var2' test_file1 > test_file2. My end result should be that test_file2 should have records from line number between... (2 Replies)
Discussion started by: Nishithinfy
2 Replies

3. Shell Programming and Scripting

Pass command line arguments to awk

I am trying to pass max as a sommand line argument when I call awk. Made the modification in the BEGIN but it is not working I'm getting an error as below: awk: txsrx.awk:82: (FILENAME=jcd.tx FNR=4161) fatal: cannot open file `40' for reading (No such file or directory) Somehow it... (2 Replies)
Discussion started by: kristinu
2 Replies

4. Shell Programming and Scripting

How to pass a field from awk in a pipe?

Thanks in advance : ) I try for a long time searching for a way to split a large gzip csv file into many gzip files (except for the last sub-file which is to joint the next big file's children.) All the subfiles are to be named by the field. But I only managed to split them into the... (9 Replies)
Discussion started by: Kingsley
9 Replies

5. Shell Programming and Scripting

Pass Parameters to awk command

I need to pass values at runtime for the below awk command where l is the length and partial.txt is the file name. awk -v l=285 '{s="%-"l"s\n";printf(s,$0);}' partial.txt > temp1.txt; (5 Replies)
Discussion started by: Amrutha24
5 Replies

6. Shell Programming and Scripting

Cannot pass rsh and awk command into a variable

Hello, I'm having some issues getting a home dir from a remote server passed to a variable. Here is what I have so far: rsh server "(ls -ld /home*/user | awk '{print \$9}')" /home3/userThat works fine and brings back what I need. But when I try to add it to a variable it goes all... (3 Replies)
Discussion started by: elcounto
3 Replies

7. Shell Programming and Scripting

How to pass filename as arguement to awk command?

Hi, I am facing one issue. The awk command works fine if i hardcode the file name but if is pass it as an arguement it doesn't work. For e.g:Below commands works fine awk -v A="$type" '{F=substr($0,23,8) "_LTD_" A ".txt"; print $0 >> F; close(F) }' RL004.txt But the below command does not... (2 Replies)
Discussion started by: Neelkanth
2 Replies

8. Shell Programming and Scripting

How to pass command line arguments to awk program?

#!/bin/awk -f BEGIN { FS=":"; } { if ( $7 == "" ) { print $1 ": no password!"; } } I want to execute this program for a particular user to check for his password from the file /etc/passwd (as the input file) and the user details to be given... (1 Reply)
Discussion started by: sri.phani
1 Replies

9. Shell Programming and Scripting

awk command not getting executed in shell script

I am able to execute awk command from shell prompt. but the same command is not getting executed when written and run in a bash script the command from bash cmd prompt. awk '/world/{for (i=2; i<NF; i++) printf $i " "; print $NF}1' myfile >tmp$$ ; mv tmp$$ myfile file: # hello world my... (4 Replies)
Discussion started by: ashima jain
4 Replies

10. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies
DATETIMEINTERFACE.GETTIMESTAMP(3)					 1					 DATETIMEINTERFACE.GETTIMESTAMP(3)

DateTime::getTimestamp - Gets the Unix timestamp

       Object oriented style

SYNOPSIS
public int DateTime::getTimestamp (void ) DESCRIPTION
int DateTimeImmutable::getTimestamp (void ) int DateTimeInterface::getTimestamp (void ) Procedural style int date_timestamp_get (DateTimeInterface $object) Gets the Unix timestamp. PARAMETERS
This function has no parameters. RETURN VALUES
Returns the Unix timestamp representing the date. EXAMPLES
Example #1 DateTimeInterface.getTimestamp(3) example Object oriented style <?php $date = new DateTime(); echo $date->getTimestamp(); ?> Procedural style <?php $date = date_create(); echo date_timestamp_get($date); ?> The above examples will output something similar to: 1272509157 NOTES
Using U as the parameter to DateTime.format(3) is an alternative when using PHP 5.2. SEE ALSO
DateTime.setTimestamp(3), DateTime.format(3). PHP Documentation Group DATETIMEINTERFACE.GETTIMESTAMP(3)
All times are GMT -4. The time now is 07:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy