Different output for awk command on Linux & HP-UX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Different output for awk command on Linux & HP-UX
# 1  
Old 07-31-2014
Oracle Different output for awk command on Linux & HP-UX

I am using an awk command to extract a particular portion of a string. Below is the command and its output on a Linux system:

Code:
oracle@host1:/tmp [default] (/home/oracle)
$uname -a
Linux host1 2.6.32-279.39.1.el6.x86_64 #1 SMP Fri Nov 15 05:38:26 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

oracle@host1:/tmp [default] (/home/oracle)
$echo "/u01/app/oracle/product/11.2.0.3/bin/tnslsnr;LISTENER;-inherit"|awk -F'/' '{for(i=1;i<NF;i++)NF=6;print $0}'|tr ' ' '/'
/u01/app/oracle/product/11.2.0.3


But the same command doesn't give desired output on an HP-UX system.
Below is the output from HP-UX System

Code:
[default](host2)/home/oracle-> uname -a
HP-UX host2 B.11.31 U ia64 1553842798 unlimited-user license

[default](host2)/home/oracle-> echo "/u01/app/oracle/product/11.2.0.3/bin/tnslsnr;LISTENER;-inherit"|awk -F'/' '{for(i=1;i<NF;i++)NF=6;print $0}'
/u01/app/oracle/product/11.2.0.3/bin/tnslsnr;LISTENER;-inherit
[default](host2)/home/oracle->

Can you guys help me understand why this command is not working on HP-UX. Also how do i get same result on HP-UX
# 2  
Old 07-31-2014
I don't know anything about HP-UX, but your awk- version might not like the NF assignment. Try
Code:
echo "/u01/app/oracle/product/11.2.0.3/bin/tnslsnr;LISTENER;-inherit"|awk -F'/' -vOFS=\/ '{print $1,$2,$3,$4,$5,$6}'

This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-31-2014
Since you haven't changed anything to reconstruct the line, you get the output. Try $1 = $1
Code:
echo "/a/b/c/d/e/f/g/r/d/c/g" | awk -F '/' '{NF=6; $1=$1}1' OFS=/

This User Gave Thanks to SriniShoo For This Post:
# 4  
Old 07-31-2014
Hi Srinishoo,
Can you please explain me your command
what does $1=$1}1' mean in the below code?

Code:
echo "/a/b/c/d/e/f/g/r/d/c/g" | awk -F '/' '{NF=6; $1=$1}1' OFS=/

# 5  
Old 07-31-2014
On Linux you're most likely running mawk or GNU awk, both of which will re-calculate $0 if you assign to a field (or change NF, although that might depend on the version).

Whatever HP-UX is using probably does not (AIX awk doesn't, for instance) - you'd need to output the fields individually as RudiC suggested.
This User Gave Thanks to CarloM For This Post:
# 6  
Old 07-31-2014
One more command, can someone help me in modifiying this command to work on HP-UX system

On Linux:

Code:
#->  echo "/u01/app/oracle/diag/tnslsnr/hpuxdgl1/listener/alert/log.xml"|awk -F'/' '{for(i=1;i<=NF;i++) if ($i ~ /diag/) NF=i;print $0}' OFS=/
/u01/app/oracle/diag

On HP-UX

Code:
$ echo "/u01/app/oracle/diag/tnslsnr/hpuxdgl1/listener/alert/log.xml"|awk -F'/' '{for(i=1;i<=NF;i++) if ($i ~ /diag/) NF=i;print $0}' OFS=/
/u01/app/oracle/diag/tnslsnr/hpuxdgl1/listener/alert/log.xml

---------- Post updated at 07:11 PM ---------- Previous update was at 07:07 PM ----------

Please ignore my latest query..i think i could figure out the way get same result on HPUX

Code:
 echo "/u01/app/oracle/diag/tnslsnr/hpuxdgl1/listener/alert/log.xml"|awk -F'/' '{for(i=1;i<=NF;i++) if ($i ~ /diag/) NF=i;$1=$1}1' OFS=/
/u01/app/oracle/diag

Srinishoo,

Your solution is working for me, but can you please explain me what does $1=$1 stand for ?
# 7  
Old 07-31-2014
When you are printing the entire line, even though you make changes to the number of fields, you have to make changes within the line to reflect new number of fields
Here, $1=$1 is assigning the value of first field to the first field...
You can replace that part with $2=$2 as well
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Xalan & Xerces issues for Oracle Linux 6.6 & Solarisstudio12.3 C++ compiler for Linux

Hi Team, I am facing issue while using Xalan & Xerces for my application. Below are my environment details i am using :- Platform:- Oracle Linux 6.6 Compiler :- solarisstudio12.3 C++ compiler for Linux Below are the versions of Xalan & Xerces source code used to build the shared object... (0 Replies)
Discussion started by: agrachirag
0 Replies

2. Shell Programming and Scripting

Linux csh script going to Suspended (tty output) when running with & (bg)

i have strange behavior i have csh file that run java process something like this : run_server.csh #!/usr/bin/tcsh java -Dtest=testparam -cp ${TEST}/lib/device.jar:${TEST}/conf:${TEST}/lib/commons-logging-1.1.1.jar com.device.server when i run it like this :... (7 Replies)
Discussion started by: umen
7 Replies

3. Shell Programming and Scripting

If && command giving wrong output

Hi All, I am trying to run a script which will search for 2 strings(stopped,started) in a text file and echo an output depending on below condition -bash-3.2$ cat trial1.txt v ggg f -bash-3.2$ cat trial1.sh VAR9=` grep 'stopped' /tmp/trial1.txt` VAR10=` grep 'started'... (4 Replies)
Discussion started by: srkmish
4 Replies

4. Shell Programming and Scripting

Check & use output of svcs command

Hello Dear Friends, I need to check output of svcs command and so the status of some instances. -bash-3.00$ svcs -a | grep rfe online Aug_04 svc:/application/rfe/rfe_master_3:default online Aug_04 svc:/application/rfe/rfe_master_4:default as you can see there are two... (1 Reply)
Discussion started by: EAGL€
1 Replies

5. Shell Programming and Scripting

awk help: Match data fields from 2 files & output results from both into 1 file

I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6. Below is an... (5 Replies)
Discussion started by: ambroze
5 Replies

6. Shell Programming and Scripting

Want to sort a file using awk & sed to get required output

Hi All, Need Suggestion, Want to sort a file using awk & sed to get required, output as below, such that each LUN shows correct WWPN and FA port Numbers correctly: Required output: 01FB 10000000c97843a2 8C 0 01FB 10000000c96fb279 9C 0 22AF 10000000c97843a2 8C 0 22AF 10000000c975adbd ... (10 Replies)
Discussion started by: aix_admin_007
10 Replies

7. Shell Programming and Scripting

Awk & sed query for output

Hello, I have a file. its content are like below. mdn:87439842 imsi:23082038203 Ctime:12082010 01:20:10 mdn:9324783783 imsi:402349823322 Ctime: 12072010 01:20:10 mdn:87439842 imsi:23082038203 Ctime: 23072010 01:20:10 mdn:87439842 imsi:23082038203 Ctime:18072010 01:20:10 mdn:87439842... (3 Replies)
Discussion started by: Sanket11
3 Replies

8. Shell Programming and Scripting

manipulate & format the output of spool command

Hi All, I am spooling the data some sql queries into a single file but wanted to know how to format the data of the file generated by spool. #!/bin/sh unset -f USAGE USAGE () { clear echo "############################USAGE#######################\n" echo "Incorrect number of... (2 Replies)
Discussion started by: ss_ss
2 Replies

9. Shell Programming and Scripting

Net::SSH::Perl->Execute any unix command & display the output in a proper form

Net::SSH::Perl ...... how to print the output in a proper format my $cmd = "ls -l"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output... (2 Replies)
Discussion started by: gsprasanna
2 Replies
Login or Register to Ask a Question