Insert a function on an script's output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert a function on an script's output
# 1  
Old 07-15-2010
Insert a function on an script's output

Hi, I have this code:

Code:
#Convert epoch2date
getdate()
{
perl -e '
    use POSIX qw(strftime);
    $mydate = strftime "%c", localtime($ARGV[0]); 
    print $mydate; ' $1
}   

lsuser -a time_last_login gecos $username  |awk '{print $1,$2,$3,$4}'|sed -e 's/gecos=/  Nombre: /' -e 's/time
_last_login=/ultimo_login=/'

and its Output:

Code:
acc17 ultimo_login=1202905371   Nombre: User1
acc18 ultimo_login=1203356871   Nombre: user2
orion ultimo_login=1145539155   Nombre: User3
tomcat ultimo_login=1164038769   Nombre: User4
acc19 ultimo_login=1203334238   Nombre: User5

I want to convert

Code:
acc17 ultimo_login=Thu Jul 15 15:16:11 CEST 2010   Nombre: User1
acc18 ultimo_login=Mon Feb 18 18:47:51 CET 2008  Nombre: user2
orion ultimo_login=Thu Apr 20 15:19:15 CEST 2006 Nombre: User3
tomcat ultimo_login=Mon Nov 20 17:06:09 CET 2006 Nombre: User4
acc19 ultimo_login=Mon Feb 18 12:30:38 CET 2008 Nombre: User5

How can I use this function from the command output above?

thanks
ISrael.

Moderator's Comments:
Mod Comment Use [CODE] tags, not [QUOTE] tags

Last edited by Scott; 07-16-2010 at 06:58 AM..
# 2  
Old 07-15-2010
Code:
lsuser -a time_last_login gecos $username |
awk '{print $1,$2,$3,$4}' |
sed -e 's/gecos=/ Nombre: /' -e 's/time_last_login=/ultimo_login=/' |
while read ACCOUNT LOGIN NUM USER; do echo $ACCOUNT ${LOGIN%%[0-9]*} $(getdate ${LOGIN##*=}) $NUM $USER; done

I've assumed that you have created the "getdate" function in the Bash shell. The function invocation can be run as a shell command in that case.

tyler_durden
# 3  
Old 07-16-2010
Worked!! Very nice tyler.. thanks a lot!

regards
israel
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

2. Shell Programming and Scripting

Shell Script function to use script name for log file output

Hi Team - I"m very new to Shell Scripting so I have a rather novice question. My forte is Windows Batch Scripting so I was just wondering what the Shell Script equivalent is to the DOS command %~n? %~n is a DOS variable that dispayed the script name. For instance (in DOS): REM... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

3. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

4. Shell Programming and Scripting

Insert output from a file to beginning of line with sed

Hi I've been trying to search but couldn't quite get the answer I was looking for. I have a a file that's like this Time, 9/1/12 0:00, 1033 0:10, 1044 ... 23:50, 1050 How do I make it so the file will be like this? 9/1/12, 0:00, 1033 9/1/12, 0:10, 1044 ... 9/1/12, 23:50, 1050 I... (4 Replies)
Discussion started by: diesel88
4 Replies

5. Shell Programming and Scripting

Script to insert a function into a C source file

Hello, I think I need sed, but perhaps awk could help. I am trying to add a function to a C source file based off a struct declaration. for example: struct Rational { int numerator; int denominator; }; becomes struct Rational (4 Replies)
Discussion started by: afulldevnull
4 Replies

6. Shell Programming and Scripting

Insert shell command into first line of output file

How can I insert the command executed on the shell into the first line of my output file? For example if I execute; zcat *.gz |grep “User5501” > users.out How can I make my users.out look like; zcat *.gz |grep “User5501” > users.out User5501 PA User5501 UA User5501 ZA... (3 Replies)
Discussion started by: lewk
3 Replies

7. Programming

Oracle Database: INSERT INTO with TO_DATE function

Hello, I am writting a procedure in shell script as, set serveroutput on declare date_gen DATE := $DATEGEN; begin INSERT INTO TBL1 ( EMPNAME,EMPID,EMPBDATE) VALUES($EMPNAME,$EMPID,TO_DATE(date_gen,'YYYY-MM-DD')); end; / Where DATEGEN is unix string variable which I need to use into... (10 Replies)
Discussion started by: Poonamol
10 Replies

8. Shell Programming and Scripting

ksh script that echo " please insert your name " and store the output to a login.log file.

Hello All Nice to meet you all here in this forum, it's my 1rst time here i'm asking about a little issue that i face i added a ksh script that echo " please insert your name " and store the output to a login.log file. the script is working fine with normal telnet but Xstart is not working... (8 Replies)
Discussion started by: islam.said
8 Replies

9. Shell Programming and Scripting

Insert output into file at line number

I need to insert the output of a script into a specific line number of a txt file. I've read the Sed man page and searched the forums and it's not immediately clear how I would go about doing this. (4 Replies)
Discussion started by: pluto7777
4 Replies

10. Shell Programming and Scripting

Insert a function in a jsp file using Shell scripting

Greetings to all.I am new to the forum as well as to UNIX as well.I have a jsp file which has the following selectedStartMonth = request.getParameter( "startMonth" ); selectedStartDay = request.getParameter( "startDay" ); selectedStartYear = request.getParameter( "startYear" );... (3 Replies)
Discussion started by: 20033716
3 Replies
Login or Register to Ask a Question