Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
One problem with the use of sed in simple text substitutions is that sed will intepret some characters as regular expression operators. For example, we might try to change just the punctuation in our earlier example:
echo Hello world. > myFile.txt
~/UnixCourse/scriptAsst/sub1 . ! myFile.txt
cat myFile.txt
and are likely to find
!!!!!!!!!!!!
in myFile.txt instead of the desired "Hello world!".
Create a new script, sub2, taking the three parameters, that treats the string to be replaced as plain text instead of as a regular expression.
The 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
Hint 1: Put the target string (the one to be replaced) into a shell variable (e.g., $target). Then use a sed command to rewrite any of the "special" regular expression characters
[ ] ^ * + . $ \ -
into "safe" forms of those same characters by adding backslashes in front (e.g., \*) or surrounding them by [ ] (e.g.,[*]). Store that rewritten version of the target string in 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.
Again, when you think you have this ready, give the command:
~cs252/bin/scriptAsst.pl
to check your scripts so far.
2. Relevant commands, code, scripts, algorithms:
Unix library
3. The attempts at a solution (include all code and scripts):
my code is:
It seems like "*" is not passing through as a parameter?
error messase:
"sub2 produced incorrect output on test 19: /home/bnaranjo/UnixCourse/scriptAsst/sub2 'l*' 'L' '_king cobra.dat'
Any help is appreciated, thank you! 4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Old Dominion University, Virginia Beach(VA), USA, Zeil, cs 252
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Generalize your sub2 script, producing a new script sub3 that will apply a substitution to any number of files... (16 Replies)
Hi
I probably dont have GNU extended sed in my SUNOS . and its creating lot of problems
ex:
a simple sed command like this is not working
sed '/WORD/ a\
sample text line 1 \
sample text line 1
' filename
sed: command garbled: /WORD/ a
I took precaution to have a new line after... (11 Replies)
Morning all
I've got loads of scripts but the names are too long! I've stuck the list in a flat file (names) and I'm trying to read that in line by line and create the new names (in to directory new) from the list. It looks like this:
xargs -n1 -I{} <names cat {} | sed... (1 Reply)
Hi, I was hoping that someone could help me. I have a problem that i am trying to work on and it requires me to change text within multiple files using sed. What i have so far is
!/bin/sh
File1="$3"
File2="$4"
File3="$5"
testNum="$File1"
while test "$testNum" <= "$File3";
do
echo... (12 Replies)
Hi, I was hoping that someone could help me. I have a problem that i am trying to work on and it requires me to change text within multiple files using sed. I use the program to change an occurance of a word throughout different files that are being tested. At first i had to Create a new script,... (1 Reply)
Hi All,
After reading that the sort command in Linux can be made to use many processor cores just by using a simple script which I found on the internet, I was wondering if I can use similar techniques for programs like the awk and sed?
#!/bin/bash
# Usage: psort filename <chunksize>... (7 Replies)
I am having a lot of trouble, wasting a lot of time trying to get sed script files to run without problem. I have a list of scripts I want to run on a text file to turn it into a viewable html file for my mobile phone. Each of the single scripts when run in order/sequence one after another on the... (4 Replies)
Hello gurus,
I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script.
i m looking for something like this
call 3.1;
If 3.1 = "complete" then
call 3.2;
if 3.2 = ''COMPlete" then
call 3.3;
else
exit
The... (1 Reply)
Hi.
In a simple sed script i have number signs - #. But i can't find any description on their functionality. One thing that i find is that # in sed scripts can mean comment if it is placed in the beginning of the line.
I thought may be this undocumented(for me) behavior refers to regular... (1 Reply)