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
Need help in substitution!!!! uLearner UNIX for Dummies Questions & Answers 3 03-06-2008 07:21 PM
Bad Substitution D_Redd74 Shell Programming and Scripting 3 02-07-2007 05:48 PM
ksh substitution solea Shell Programming and Scripting 2 08-09-2004 05:30 AM
sed substitution jo_aze UNIX for Dummies Questions & Answers 3 06-23-2002 09:32 PM
substitution supercbw Shell Programming and Scripting 1 06-07-2002 03:07 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-15-2008
klut klut is offline
Registered User
  
 

Join Date: Jan 2008
Location: Prague
Posts: 7
Smile AWK substitution

I need to copy field 2 to field 3 for only those records that have the 1st field equal to account

e.g. file

account|123|789|xxx|yyy|zzz|...
account_group|444|555|xxx|yy|zz|....
account|456|901|aaa|bbb|ccc|.....

after running awk script should look like

account|123|123|xxx|yyy|zzz|...
account_group|444|555|xxx|yy|zz|....
account|456|456|aaa|bbb|ccc|.....
  #2 (permalink)  
Old 01-15-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
Code:
awk '{FS="|";if ( $1 == "account" ){$3 = $2}{print $0}}' file
should work
  #3 (permalink)  
Old 01-15-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Code:
awk '$1=="account"{$3=$2}1' FS="|" OFS="|" filename
or

Code:
awk '($1=="account"&&$3=$2)||1' FS="|" OFS="|" filename
Use nawk or /usr/xpg4/bin/awk on Solaris.
  #4 (permalink)  
Old 01-15-2008
ramen_noodle ramen_noodle is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 251
Code:
awk 'BEGIN {FS="|"; OFS="|"} {if ($1 == "account") {$3 = $2}; print}'
  #5 (permalink)  
Old 01-15-2008
klut klut is offline
Registered User
  
 

Join Date: Jan 2008
Location: Prague
Posts: 7
Cheers for that, seems all the solutions work
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 02:04 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