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
Replace the file using sed senthil_is Shell Programming and Scripting 5 11-20-2008 07:58 AM
replace nth value in xml file subin_bala Shell Programming and Scripting 4 06-18-2008 02:39 PM
replace words in file based on another file kinmak Shell Programming and Scripting 9 05-07-2008 05:06 AM
Replace word in a file sasiharitha UNIX for Dummies Questions & Answers 3 12-05-2007 01:11 AM
serach and replace file name in the path in a remote xml file kiranreddy1215 Shell Programming and Scripting 1 11-12-2007 11:31 AM

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 05-16-2007
lesstjm lesstjm is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 59
Replace a Value in File

I have a pipe delimited file. I want to replace the contents of field 19 with the value USD. Does anyone know the command for this?
  #2 (permalink)  
Old 05-16-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Lesstjm,
Here is one solution using "sed":
Code:
sed -e 's/|/USD|/19' -e 's/\(.*\)|.*USD/\1|USD/' input_file
  #3 (permalink)  
Old 05-16-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Code:
awk 'BEGIN{FS="|"}{$19="USD";$0=$0;print}' file

Last edited by ghostdog74; 05-16-2007 at 10:02 AM.. Reason: forgot the pipe
  #4 (permalink)  
Old 05-16-2007
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
Try that:
Code:
awk -F'|' '{$19="USD"; print}' inputfile
  #5 (permalink)  
Old 05-16-2007
lesstjm lesstjm is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 59
Did Not Work

awk 'BEGIN{FS="|"}{$19="USD";$0=$0;print}' file is giving me an error

$ awk 'BEGIN{FS="|"}{$19="USD";$0=$0;print}' US_RETAIL_WIRE_TRANS_20070504_00.TST
awk: can't set $0
record number 1


The next one awk -F'|' '{$19="USD"; print}' inputfile
is removing all of the pipes.

The sed command worked though.

Thanks for your help
  #6 (permalink)  
Old 05-16-2007
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
Quote:
Originally Posted by lesstjm
The next one awk -F'|' '{$19="USD"; print}' inputfile
is removing all of the pipes.
The Output Field Separator must be set to '|'
Code:
awk 'BEGIN {FS=OFS="|"} {$19="USD"; print}' inputfile
Jean-Pierre.
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 12:44 PM.


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