The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Postfix force sender ("From:" field) +Yan UNIX for Advanced & Expert Users 0 01-15-2009 10:57 AM
A question/problem about oracle "tns listener" and "enterprise manager" talipk UNIX for Advanced & Expert Users 1 12-03-2008 07:55 AM
A question/problem about oracle "tns listener" and "enterprise manager" talipk UNIX and Linux Applications 0 12-01-2008 03:08 PM
how can i replace "(", "\" "+" in a file mail2sant Shell Programming and Scripting 3 04-22-2008 11:10 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM

Reply
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 06-12-2009
VGR VGR is offline
Registered User
  
 

Join Date: Mar 2008
Location: kolkata
Posts: 34
Additional question to "awk to replace particular field"

I guess it was getting a little messy on the other post so here goes:
Link to previous post for Question:
awk to replace particular field

Continuation of Question
hey i was messing around a bit ... made me wonder...
If the error_correction.txt file had 3 columns,:

VenoM,Venom,Antivenom
nos,NOS,N2O
..
.
.
.


Now Suppose i have an if statement and depending on it i have to choose a value from column 2 or column 3, to replace the value in the main datafile.
How do i do this?
  #2 (permalink)  
Old 06-18-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,884
Code:
cat file | awk '{ if (condition_x) $2="new column two" else $3="new column three"; print $0; }' >file.new && mv file.new file
Reply

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 04:08 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