> passing variables to sed inside script | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

passing variables to sed inside script

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-23-2005
Daniel234 Daniel234 is offline
Registered User
 
Join Date: Nov 2005
Last Activity: 24 November 2005, 6:15 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
passing variables to sed inside script

I am trying to pass a regular expression variable from a simple script to sed
to remove entries from a text file

e.g.

a='aaaa bbbb cccc ...|...:'

then executing sed from the script

sed s'/"'$a"'//g <$FILE > $FILE"_"1

my output file is always the same as the input file !!

any hints / pointers are aprreciated
Sponsored Links
    #2  
Old Unix and Linux 11-23-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
 
Join Date: Jan 2005
Last Activity: 27 September 2011, 12:36 PM EDT
Posts: 683
Thanks: 0
Thanked 4 Times in 4 Posts
eval should accomplish what you wish.
Sponsored Links
    #3  
Old Unix and Linux 11-24-2005
Daniel234 Daniel234 is offline
Registered User
 
Join Date: Nov 2005
Last Activity: 24 November 2005, 6:15 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I am not to certain what you mean and how to pass eval the command value
    #4  
Old Unix and Linux 11-24-2005
Ygor's Unix or Linux Image
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 15 May 2015, 11:55 AM EDT
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 114 Times in 99 Posts
Use awk instead of sed...
Code:
awk '{gsub(a,b);print}' a="$a" b="" file1 > file2

Sponsored Links
    #5  
Old Unix and Linux 11-24-2005
Daniel234 Daniel234 is offline
Registered User
 
Join Date: Nov 2005
Last Activity: 24 November 2005, 6:15 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
thanks for the hint, bit of modification got the script working Linux
Sponsored Links
    #6  
Old Unix and Linux 11-24-2005
vishnu_vaka's Unix or Linux Image
vishnu_vaka vishnu_vaka is offline
Registered User
 
Join Date: Nov 2005
Last Activity: 9 March 2011, 9:29 AM EST
Location: Hyderabad
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL

use
double qoutes instead of single quotes wil solve the problem
sed "s/$a//g" inputfile>tempfile;mv tempfile inputfile


will give the desired result
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem passing a search pattern to AWK inside a script loop quinestor Shell Programming and Scripting 14 03-14-2012 11:12 AM
passing arguments to unix command or script inside tclsh Blue_shadow Shell Programming and Scripting 1 01-10-2012 04:15 PM
passing variables to sed function in a script .... shweta_d Shell Programming and Scripting 2 06-05-2007 06:13 AM
passing variables to awk from ksh script rein Shell Programming and Scripting 3 08-11-2005 11:29 AM



All times are GMT -4. The time now is 11:18 AM.