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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Replacement for sed dbsurf Shell Programming and Scripting 0 01-25-2008 02:47 PM
Regarding Replacement rajx UNIX for Dummies Questions & Answers 2 05-22-2007 06:19 AM
variable replacement ppass Shell Programming and Scripting 4 06-01-2005 07:18 AM
Replacement using sed handak9 UNIX for Dummies Questions & Answers 5 07-13-2004 08:28 AM
cpu replacement. help IMPTRUE UNIX for Dummies Questions & Answers 3 07-25-2003 05:40 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: May 2008
Posts: 7
Stumble this Post!
how to use a command in sed s/match/replacement

hi,

how can i make use of a command in the replacement segment..

cat a | sed '/^[[:digit:]*]\{3\}$/{
s/\(.*\)/REPLACEMENT/g
}'

suppose if I want to use a awk command in the replacement section , how to achieve that ?

Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-10-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Stumble this Post!
Use backticks, double quotes and remove cat command (is useless):

Code:
sed "/^[[:digit:]*]\{3\}$/{
s/\(.*\)/`awk '{ blah blah blah }' awk_input_file.txt`/g
}" a
But I highly recommend to put the awk result into a variable and pass that variable in sed script, especially if the awk code is complex:

Code:
VAR=`awk '{ blah blah blah }' awk_input_file.txt`
sed "/^ ... $/s/.*/${VAR}/g" sed_input_file.txt
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0