The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Changing one column of delimited file column to fixed width column manneni prakash Shell Programming and Scripting 5 06-22-2009 06:27 AM
How to combined file? jantzen16 Shell Programming and Scripting 7 12-25-2008 05:46 AM
How to combined to file with their values jantzen16 Shell Programming and Scripting 5 12-22-2008 10:03 AM
printing in certain column based on some result kumar_amit Shell Programming and Scripting 6 12-12-2008 03:51 PM
Help with script printing column with space n3al10 Shell Programming and Scripting 4 12-16-2007 05:42 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-08-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
Awk not printing the last combined column

Code:
nawk -F "|" 'FNR==NR {a[$1]=$2 OFS $3 OFS $4 OFS $5 OFS $6;next}\
{if ($5 in a)print $1,"test",$5,a[$5], $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 ; \
else print $1,"Database",$5 OFS OFS OFS OFS OFS OFS $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 }' OFS="|" \
file1 file2 > file3
This works fine except the last part where
Code:
$2-$3-$4
i want to print $2$3$4 in one field seperated by -
it is printing 0

Appreciate help
  #2 (permalink)  
Old 05-08-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
why do you think it's doing that?
  #3 (permalink)  
Old 05-08-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
Quote:
Originally Posted by vgersh99 View Post
why do you think it's doing that?
I think i should use printf but i am not aware how to use it while printing an array.

I dont know why it is doing that.
  #4 (permalink)  
Old 05-08-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Hint: Is '-' a 'dash' or a 'minus' in your context?
  #5 (permalink)  
Old 05-08-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
Quote:
Originally Posted by vgersh99 View Post
Hint: Is '-' a 'dash' or a 'minus' in your context?

Actually i was about to post

i myself also figured it out and used
Code:
$2"-"$3"-"$4
Thanks vgersh99 and devtakh
  #6 (permalink)  
Old 05-08-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
Quote:
Originally Posted by zenith View Post
Code:
nawk -F "|" 'FNR==NR {a[$1]=$2 OFS $3 OFS $4 OFS $5 OFS $6;next}\
{if ($5 in a)print $1,"test",$5,a[$5], $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 ; \
else print $1,"Database",$5 OFS OFS OFS OFS OFS OFS $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 }' OFS="|" \
file1 file2 > file3
This works fine except the last part where
Code:
$2-$3-$4
i want to print $2$3$4 in one field seperated by -
it is printing 0

Appreciate help
use $2"-"$3"-"$4 instead or it will be treated as minus and try to substract.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0