Hide status value from awk system command

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Hide status value from awk system command
# 1  
Old 10-12-2009
Hide status value from awk system command

When i use the system( ) function inside a awk, i am getting the ouput with a 0 appended in a new line.

Can someone guide me to eliminate the extra line containing 0.

Ex :

awk -F"|" '{print system("convert.sh" $1}'

The output is displayed with 0 in a new line.


I expect the o/p as follows :


# 2  
Old 10-12-2009
A possible workaround:

awk -F"|" '{"convert.sh" $1|getline converted; print converted}'

# 3  
Old 10-12-2009
Thanks for your help, but quiet unfortunately doesn't work. Is there any other help.
# 4  
Old 10-12-2009
Originally Posted by muruganksk
Thanks for your help, but quiet unfortunately doesn't work. Is there any other help.
Is that the o/p the doesn't return the expected or the awk command that fails? What error message?

Give it another try like this:
 awk -F"|" '{sprintf("convert.sh %s",$2) |getline cvrtd;print cvrtd}' file

# 5  
Old 10-12-2009
That's a weird print command. The system function returns the exit code of the command, the 0 is the return code of your command.

What are you trying to achieve? Clarify your question.
Post your code within code tags and be more precise, the code you posted isn't correct.
# 6  
Old 10-12-2009
Thanks a lot for the valuable help..

The command that you gave last worked fine, but then the issue am facing now is i need to print some values before the execution of script.

This is what actually am trying for :

awk -F"|" '{print $1,$2,$3,system("echo" $4),$5,$6,system("convert.sh" $12 $13 $9 $10)}' input_file

when i was trying this command i was facing the issue with the exit status.

But then the command you provided replaced the system , but then i am not able to get the previous values printed.

Please advise..

---------- Post updated at 10:42 PM ---------- Previous update was at 10:23 PM ----------

To make it more precise :

The input file content:

file name : input_file

2012                 | TEST | TEST1   |              14031 |      276500 |  TST2               |  334FAAA     |       124706 |       274506 |      2142767 |       346329 |  x'55'         |  x'4F'                 |            0 |       40 |        0

Code tried :

Code :

awk -F"|" '{print $1,$2,$3,system("echo" $4),$5,$6,system("convert.sh" $12 $13 $9 $10)}' input_file

Expected output :

2012 TEST TEST1 14031 276500 TST2 2012 TEST TEST1 14031 276500 TST2 v7126-6528-6230-6530-YOA1-274506-85-79-2142767

the last value v7126-6528-6230-6530-YOA1-274506-85-79-2142767 is the output from the convert.sh.

But the output that i currently get is :

2012 TEST TEST1 14031 
0 276500 TST2 v7126-6528-6230-6530-YOA1-274506-85-79-2142767

Thanks !

---------- Post updated 10-13-09 at 12:15 AM ---------- Previous update was 10-12-09 at 10:42 PM ----------

Can somebody help??

Last edited by Franklin52; 10-12-2009 at 02:15 PM.. Reason: Please use code tags!!
# 7  
Old 10-12-2009
How about something like this:

awk 'BEGIN { FS = "[ |]+" } { "./convert.sh " $12 $13 $9 $10 | getline con; "echo " $4 | getline ech; print $1,$2,$3, ech, $5, $6, con; }' input_file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sprintf and system command in awk

Hello Friends, I'm trying something hard (for me) to create a report script,normally the following script works: Echos are just for cosmetic touch, echo -n "\n-----\t----------\t-------------\t\t--------------\t\t--------\n COUNT\tEVENT_TYPE\tRESPONSE_CODE\t\tINTERNAL_ERROR\t\tFLOWNAME... (7 Replies)
Discussion started by: EAGL€
7 Replies

2. Shell Programming and Scripting

Awk: System command not working in awk

Hi, I have around 10 files in a folder in which I want to change the file format from tab(\t) to pipe(|) with some changes in the fields as well. Below is the code, while tmp file is getting generated but move command is not working, please help Following is the code awk -F"\t" '{print... (2 Replies)
Discussion started by: siramitsharma
2 Replies

3. Ubuntu

Hide command details in top?

I am pulling data from remote SFTP server via LFTP. I really like its features. I have executed following command through screen. lftp -u xxxxx,xxxxx -e "set sftp:connect-program 'ssh -a -x -i /sftp/user/downloads/.ssh/id_dsa';mirror -vvv -c /data/ /sftp/user/downloads/2014_ic; quit"... (1 Reply)
Discussion started by: zsycho
1 Replies

4. Programming

How to hide from UNIX strings - obfuscate or hide a literal or constant?

Hi, I need to somehow pipe the password to a command and run some SQL, for example, something like echo $password | sqlplus -s system @query01.sql To make it not so obvious, I decided to try out writing a small C program that basically just do echo $password. So now I just do x9.out | sqlplus... (8 Replies)
Discussion started by: newbie_01
8 Replies

5. Shell Programming and Scripting

awk - System command not working

dear All, my awk system command isn't working or rather I'm missing something in my command. Appreciated , if anyone can assist me what exactly I'm missing ?? awk ' /^/ { > c=split($3,a,"/") ;for(n=1; n<=c; ++n) > { > if (system("test -d" /home/cubedata/20120104/"$1"/"a")) { > print... (5 Replies)
Discussion started by: manas_ranjan
5 Replies

6. Shell Programming and Scripting

hide stdout but need exit status

Hi: echo "Escriba el nombre de usuario: \c" read user lsuser -a $user 2>/dev/null || (echo "Usuario no valido en el sistema. Abortando." && exit 1) I want: - If 'lsuser -a $user' fails, script exits but hide stderr. - If 'lsuser -a $user' succeeds, script continue, and hide stdout.... (10 Replies)
Discussion started by: iga3725
10 Replies

7. Cybersecurity

how to Hide Passwords From UNIX ps Command

Hi, By reporting the process status with ps, any Unix user will see the command line arguments #ps -ef UID PID PPID C STIME TTY TIME CMD lsc 13837 13825 0 May 11 pts/17 0:01 -ksh oracle 4698 6294 0 12:00:40 ? 0:00 sqlplus -s system/manager appluser 4229 4062 0 12:00:03... (2 Replies)
Discussion started by: bhagirathi
2 Replies

8. UNIX for Advanced & Expert Users

How to hide command line parameters?

Hello I want to hide command line parameters of my programs/scripts to not to be seen with 'ps' command. How can I do that? thanks in advance. (6 Replies)
Discussion started by: xyzt
6 Replies

9. Shell Programming and Scripting

system command within awk

I was trying commands within awk. i got stuck here. i take 2 files. cat input first second third fourth fifth sixth seventh eighth ninht tenthcat add *************** Nirbhay ***************i run the command awk '{ if ( NR == 5 ) { print system("cat add") "\n" $0 } else {... (4 Replies)
Discussion started by: nirbhay
4 Replies

10. Shell Programming and Scripting

awk system() command not working

I am using Sun Solaris 5.8 I am trying to run a system command such as ls and echo inside awk, but when I run the following code system echo is not displayed. bash-2.03$ ls | awk 'BEGIN { print "first print" system("echo system echo") print "second print" ... (1 Reply)
Discussion started by: rakeshou
1 Replies
Login or Register to Ask a Question