Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-23-2005
Registered User
 
Join Date: Nov 2005
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
Registered User
 
Join Date: Jan 2005
Posts: 683
Thanks: 0
Thanked 4 Times in 4 Posts
eval should accomplish what you wish.
Sponsored Links
    #3  
Old 11-24-2005
Registered User
 
Join Date: Nov 2005
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 Staff  
Moderator
 
Join Date: Oct 2003
Location: 54.23, -4.53
Posts: 1,792
Thanks: 1
Thanked 101 Times in 91 Posts
Use awk instead of sed...
Code:
awk '{gsub(a,b);print}' a="$a" b="" file1 > file2

Sponsored Links
    #5  
Old 11-24-2005
Registered User
 
Join Date: Nov 2005
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
Registered User
 
Join Date: Nov 2005
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 03:14 AM.