Sponsored Content
Top Forums Shell Programming and Scripting Using sed to replace a string in file with a string in a variable that contains spaces Post 302374324 by vivelafete on Tuesday 24th of November 2009 07:12:25 AM
Old 11-24-2009
Using sed to replace a string in file with a string in a variable that contains spaces

Hi,

i call my shell like:
Code:
my_shell "my project name"

my script:
Code:
#!/bin/bash -vx

projectname=$1

sed s/'PROJECT_NAME  ='/'PROJECT_NAME  = '$projectname/ <test_config_doxy >temp
cp temp test_config_doxy

the following error occurres:

Code:
sed s/'PROJECT_NAME           ='/'PROJECT_NAME           = '$projectname/ <test_config_doxy >temp
+ sed 's/PROJECT_NAME           =/PROJECT_NAME           = my' project name/
sed: -e expression #1, char 54: unterminated `s' command

do i have to take the string apart by searching the spaces and do then something like:

Code:
sed s/'PROJECT_NAME           ='/'PROJECT_NAME           = '$string1' '$string2' '$string3/ <test_config_doxy >temp

or is there a clever alternative

Thanks!

---------- Post updated at 07:12 AM ---------- Previous update was at 06:05 AM ----------

sed s/'PROJECT_NAME ='/'PROJECT_NAME = '"$projectname"/ <test_config_doxy >temp

"$projectname" //just use quotation marks around the variable
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed: replace string with another string (with spaces)

Hi I have an XML file with strings XABCD, XEFGHX and XIJKLX. I would like to replace XABCDX with "This is the first string", XEFGHX with "This is the second string" and XIJKLX with "This is the third string". What is the best way to implement this? Should I have a file with the data that is... (4 Replies)
Discussion started by: zmfcat1
4 Replies

2. Shell Programming and Scripting

Help with sed matching <tag1> newline spaces <tag2> and replace the value in the same string format

Hi, I'm very new to shell scripting and have searched google and this forum for quite some time now. I have the following in my xml file: <recipients> <member>value1</member> </recipients> I need to find a string <recipients> that follows with a new-line and bunch of spaces and... (5 Replies)
Discussion started by: mgharios
5 Replies

3. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

4. Shell Programming and Scripting

Replace string in file with a variable value

Hi Fellows, I am new to shell, please help we me out in this.. i have file which some lines like this.. $$param1='12-jan-2011' $$param2='14-jan-2011' $$param3='30-jan-2011' . . .....so on.. I want to change $$param3 to '31-dec-2011'. i have variable which is storing(30-jan-2011 this... (1 Reply)
Discussion started by: victor369
1 Replies

5. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. Shell Programming and Scripting

How to replace a string with a variable in a file using sed?

I have a file having some text like: PATH_ABC=/user/myLocation I have to replace "/user/myLocation" with a session variable say, $REPLACE_PATH, where $REPLACE_PATH=/user/myReplaceLocation The following sed command is not working. It is writing PATH_ABC=$REPLACE_PATH in the file ... (2 Replies)
Discussion started by: SKhan
2 Replies

8. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

9. UNIX for Dummies Questions & Answers

How do I replace a string in file that is in a certain position with spaces?

I am trying to replace the string in position 26 through 35 of the data file with 10 spaces and I want the remaining file to stay as is, the record length is over 900 characters? I am trying to use the AWK and substr but I am not getting it formatted correctly. Before... (6 Replies)
Discussion started by: fnwine1500
6 Replies

10. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies
Gtk2::PageSetup(3)					User Contributed Perl Documentation					Gtk2::PageSetup(3)

NAME
Gtk2::PageSetup HIERARCHY
Glib::Object +----Gtk2::PageSetup METHODS
pagesetup = Gtk2::PageSetup->new pagesetup = Gtk2::PageSetup->new_from_file ($file_name) o $file_name (localized file name) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.12 pagesetup = Gtk2::PageSetup->new_from_key_file ($key_file, $group_name) o $key_file (Glib::KeyFile) o $group_name (string or undef) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.12 double = $setup->get_bottom_margin ($unit) o $unit (Gtk2::Unit) $setup->set_bottom_margin ($margin, $unit) o $margin (double) o $unit (Gtk2::Unit) double = $setup->get_left_margin ($unit) o $unit (Gtk2::Unit) $setup->set_left_margin ($margin, $unit) o $margin (double) o $unit (Gtk2::Unit) $setup->load_file ($file_name) o $file_name (string) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.14 $setup->load_key_file ($key_file, $group_name) o $key_file (Glib::KeyFile) o $group_name (string or undef) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.14 pageorientation = $setup->get_orientation $setup->set_orientation ($orientation) o $orientation (Gtk2::PageOrientation) double = $setup->get_page_height ($unit) o $unit (Gtk2::Unit) double = $setup->get_page_width ($unit) o $unit (Gtk2::Unit) double = $setup->get_paper_height ($unit) o $unit (Gtk2::Unit) $setup->set_paper_size_and_default_margins ($size) o $size (Gtk2::PaperSize) papersize = $setup->get_paper_size $setup->set_paper_size ($size) o $size (Gtk2::PaperSize) double = $setup->get_paper_width ($unit) o $unit (Gtk2::Unit) double = $setup->get_right_margin ($unit) o $unit (Gtk2::Unit) $setup->set_right_margin ($margin, $unit) o $margin (double) o $unit (Gtk2::Unit) $setup->to_file ($file_name) o $file_name (localized file name) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.12 $setup->to_key_file ($key_file, $group_name) o $key_file (Glib::KeyFile) o $group_name (string or undef) Since: gtk+ 2.12 double = $setup->get_top_margin ($unit) o $unit (Gtk2::Unit) $setup->set_top_margin ($margin, $unit) o $margin (double) o $unit (Gtk2::Unit) ENUMS AND FLAGS
enum Gtk2::PageOrientation o 'portrait' / 'GTK_PAGE_ORIENTATION_PORTRAIT' o 'landscape' / 'GTK_PAGE_ORIENTATION_LANDSCAPE' o 'reverse-portrait' / 'GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT' o 'reverse-landscape' / 'GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE' enum Gtk2::Unit o 'pixel' / 'GTK_UNIT_PIXEL' o 'points' / 'GTK_UNIT_POINTS' o 'inch' / 'GTK_UNIT_INCH' o 'mm' / 'GTK_UNIT_MM' SEE ALSO
Gtk2, Glib::Object COPYRIGHT
Copyright (C) 2003-2008 by the gtk2-perl team. This software is licensed under the LGPL. See Gtk2 for a full notice. perl v5.12.1 2010-07-05 Gtk2::PageSetup(3)
All times are GMT -4. The time now is 06:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy