Create a new script, sub2, taking three parameters...
1.) the string to be replaced
2.) the string with which to replace it
3.) the name of the file in which to make the substitution
...that treats the string to be replaced as plain text instead of as a regular expression.
Hint 1: Try to get the string to be replaced into a shell variable (e.g., $target). Then use a sed command to rewrite any special regular expression characters in that string so that they get treated as text, storing the result in a second shell variable (e.g., $newTarget). Then issue the actual command to perform the substitutions on the file.
Hint 2: For technical reasons, this task is probably easier accomplished in /bin/sh than in /bin/csh. If you insist upon using csh to run your script, you might need to solve this by writing your sed commands into a separate temparary file and using the -f option of sed to run commands from that file.
This is what I've got so far, but for some reason I keep getting the same error message...
and the error message I get is...
sed: -e expression #1, char 8: Invalid back reference
This is clearly classwork. Please review our policy on homework, and repost in the homework forum. That requires you to answer questions about the course and school.
Last edited by jim mcnamara; 07-19-2012 at 01:51 PM..
I have data that looks like this:
<Country code="US"><tag>adsf</tag><tag>bdfs</tag></Country><Country code="CA"><tag>asdf</tag><tag>bsdf</tag></Country>
I want to grab the country code save it, then drop each new "<..." onto a new line with the country code added to the beginning of each
So,... (9 Replies)
i have a text
20 21 22 23 24 25 26
i want to get 22 using sed back reference.
I have used sed 's/{6}\(..\).*/\1/'
but, it does not work.
I am missing something somewhere.
Please help. (5 Replies)
I am trying to change a single line of a special file whose comment character is ! to show a path to the file in the comment. such as:
!!HFSS and mcm path: \Signal_Integrity\Package_SI\Section_Models\C4toTrace\28nm\D6HS\SLC_5-2-5\GZ41_ICZ\NSSS\
to a different path and replace the !!HFSS... (1 Reply)
Hello all,
I am using sed to parse a particular part of a string and am having problems. I am getting the following error:
sed: -e expression #1, char 28: invalid reference \1 on `s' command's RHS
Here is the code I am using:
echo "Alarm SET:"
echo ""
echo "Date: " $DATE
echo... (4 Replies)
Hi guys, I am a newbie to shell scripting.Please help me to accomplish this task. Its very urgent,I should create a script which will do the following:
i) "cd ~joseph/ ; mkdir -p Bing/Bong ;mkdir -p Bing/Bang" and then create 15 ".txt" files with content "Bing Bang Bong" in "Bong"... (1 Reply)
My input text has the following pattens:
func_a(3,
4,
5);
I want to replace it with this:
func_b(3,
4,
5,
6);
I'm trying the following expression, but it does not work:
perl -p -e "s/func_a\((.*)?\);/func_b(\1,\n6)/s" <... (8 Replies)
Hi,
i am getting this error........
find ./ | sed '/\(*\) \(*\)/\2\1/'
Unrecognized command: /\(*\) \(*\)/\2\1/
Any idea???
regards
Apoorva Kumar (4 Replies)