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
paste each 10 lines of single column to several column nica Shell Programming and Scripting 4 01-22-2009 04:18 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
How to write data in column c0384 Shell Programming and Scripting 8 07-28-2007 06:18 PM
Replace 10th column with a new column--- Terriblly hurry ahmedwaseem2000 Shell Programming and Scripting 2 09-06-2005 02:10 AM

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 03-31-2009
prav076 prav076 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
Write a new value to a column in AWK

I have a file with columns which are separated by tabs and spaces like


Code:
111          333 444 555  7gg 
333          555 678 778  6yy

I need to write a AWK commmand , to search for a pattern in column 1 eg "111" and replace the value in column 5 with say "7kk" , I tried the assignment $5="7kk" , but if I print the line {print $0} , the column are separated only by spaces, but I want to retain the original format.

Can anyone please help me with this

Last edited by Yogesh Sawant; 03-31-2009 at 04:35 AM.. Reason: added code tags
  #2 (permalink)  
Old 03-31-2009
Shahul's Avatar
Shahul Shahul is offline
Registered User
  
 

Join Date: Aug 2008
Location: India
Posts: 175
HOpe This can help you..


Code:
$ echo "111          333 444 555  7gg"| awk '/111/ {sub($5,"7kk");print}'
111          333 444 555  7kk

Thanks
Sha
  #3 (permalink)  
Old 03-31-2009
prav076 prav076 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
Thanks a lot for your reply , but the command sub did not work
  #4 (permalink)  
Old 03-31-2009
Shahul's Avatar
Shahul Shahul is offline
Registered User
  
 

Join Date: Aug 2008
Location: India
Posts: 175
Whish OS ..you are in ?

if you are using solaris...then use nawk instead on awk command!!

Thanks
SHa
  #5 (permalink)  
Old 03-31-2009
prav076 prav076 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
Sorry I should have mentioned that the OS is Sun Solaris 5.10.
{sub($5,"7kk");print}' works in nawk

Thanks again
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 08:00 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