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

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

passing variables to sed inside script

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 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 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 11-24-2005
Ygor's Avatar
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 2 May 2014, 7:14 AM EDT
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 111 Times in 98 Posts
Use awk instead of sed...
Code:
awk '{gsub(a,b);print}' a="$a" b="" file1 > file2

Sponsored Links
    #5  
Old 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
Sponsored Links
    #6  
Old 11-24-2005
vishnu_vaka's Avatar
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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Passing variables from one script to another tcoventr UNIX for Dummies Questions & Answers 2 06-18-2002 10:57 AM



All times are GMT -4. The time now is 04:19 AM.