Asst: Shell Script to sed

Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Asst: Shell Script to sed
# 1  
Old 12-07-2013
Asst: Shell Script to sed

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 given on the command line. For example
~/UnixCourse/scriptAsst/sub3 foo bar myFile1.txt myFile2.txt myFile3.txt

should apply the same substitution throughout each of the three files named there.
Give the command:


to complete the assignment.

2. Relevant commands, code, scripts, algorithms:
Using pico for scripting in putty

3. The attempts at a solution (include all code and scripts):
My attempt at the Assignment:

for FILE in "$@"
echo $p1
echo $p2
echo "$p1" | sed -e 's/\([*.[^$]\)/\\\1/g' > temp
p1="`cat temp`"
rm temp 
echo $p1

sed "s/$p1/$p2/g" "$FILE > temp.out
mv temp.out "$FILE"

I noticed there was a previous thread about this, but with my code its not working and i dont know why.

The error im recieving is
sub3 produced incorrect output on test 37: /home/bnaranjo/UnixCourse/scriptAsst/sub3 'l*' 'L' '' '/home/bnaranjo/UnixCourse/scriptAsst/../_hippo.cpp'

I appreciate any help and anybodys time for looking at it, its my last assignment
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Old Dominion University, Norfolk(VA), USA, Zeil, csc 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).

Last edited by Scrutinizer; 12-08-2013 at 03:44 AM.. Reason: code tags
# 2  
Old 12-07-2013
There seems to be a double quote missing with the second sed command.
# 3  
Old 12-08-2013
Oh that mustve been a typing error i did, the code includes the parenthesis in my code, im sorry. Thank you for taking a look, any other ideas you could give me?

---------- Post updated at 12:19 AM ---------- Previous update was at 12:17 AM ----------

Oh that mustve been a typing error, i include the parenthesis in my code, im sorry. Thank you for taking a look, any other ideas ?
# 4  
Old 12-08-2013
I meant a double quote: ", around "$FILE" not a parenthesis (). What is not working? What is producing this error message?
# 5  
Old 12-08-2013
Yeah the double quotes you mentioned, thats whats in my original code.But im not sure what the error is, my guess maybe sed isnt working well for the last file being changed, it works fine up from 1 to 36, then at 37 it gives me trouble. It says sub3 produced incorrect output on test 37

the full error message is up in my original message up top
# 6  
Old 12-08-2013
Yes but the error message is not produced by the shell interpreting the script, or a Unix utility but by something else. We have no way of knowing what that is. What could be is that the variables in the sed statement contain a forward slash, which would mess up the command. Then you could use another character instead of the /. For example:
sed "s#$p1#$p2#g"

# 7  
Old 12-08-2013
oh yeah, i tried the sed command, still no luck, gave me the same results, i really appreciate you being patient with me and helping, i just dont know how else i could go about this, do you know how i could debug that file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on shell script (sed)

Hi Guys, I have a xml file as below where I need to find the particular XML tag(<dpath>) and delete the content of it. <?xml version="1.0" encoding="UTF-8"?> <title>XML</title><head>Ram</head><ControlCenter><doStatus>1</doStatus></ControlCenter><exitlabel>Gzip... (7 Replies)
Discussion started by: Vinoth Kumar G
7 Replies

2. Homework & Coursework Questions

Asst: Using Shell Scripts with sed

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... (1 Reply)
Discussion started by: raymondbn
1 Replies

3. Shell Programming and Scripting

SED shell script

Generate a ddl file, we have a flat file which contains many commands like REM, CREATE table, TRuncate etc This script should copy only create table statements to the ddl file. Create stmts can be in a single or multiple lines. ex:- INPUT FILE create table tbl1 (fld1,... (5 Replies)
Discussion started by: learninfo
5 Replies

4. Shell Programming and Scripting

using sed in shell script

Hi, i want to replace sub text which is in the middle of long text. let me be more clear with an example. Here is the actual text in the xml file <module-option name="principalDNSuffix">,cn=Users,dc=X,dc=Y</module-option> Now, in the above text, i want to replace all the content lying... (3 Replies)
Discussion started by: sunrexstar
3 Replies

5. Shell Programming and Scripting

using sed in shell script

Hi all, I have files with the following names; I want to rename them to ... (5 Replies)
Discussion started by: Muhammad Rahiz
5 Replies

6. Shell Programming and Scripting

Help with shell script and sed!

Hi folks, maybe somebody here can help me. I have 2 files. File A and File B. File A contains URLs leading to files on the Internet, with one URL per line; The format of the URLs on each line in File A is . File B contains only the filenames from each line in File A; One filename per line. ... (11 Replies)
Discussion started by: o0110o
11 Replies

7. UNIX for Dummies Questions & Answers

shell script - sed

Hi i have a problem how to put som lines on top or in the bottom of the text with sed. problem is that i am reading from stdin and when i have som lines starting with ++, i have to put some characters on the top of the lines starting with that ++ example of input oooo ++abcd ++befg... (1 Reply)
Discussion started by: Dun
1 Replies

8. Shell Programming and Scripting

shell script by sed

Hey everybody I need some help on how to order the data in file such as a file have first name last name and city and i would like to order them to in the same order by using sed thanks alot for your time (6 Replies)
Discussion started by: halola85
6 Replies

9. Shell Programming and Scripting

Sed command in shell script

I have a current code working(named subst1) having a user be able to type this line to substitute words using the sed command: subst1 old-pattern new-pattern filename Here is my shell script: #!/bin/bash # subst1 ARGS=3 E_BADARGS=65 if then echo "Usage: `basename $0`... (1 Reply)
Discussion started by: Todd88
1 Replies

10. Shell Programming and Scripting

grep, sed in a shell script

Hi, I have a problem with a simple script I am trying to write. I want a user to type grep, sed commands that are then stored in variables. Those variables are stored in a function, and the function is then called to execute the commands. The idea is that the user does it step by step. ... (4 Replies)
Discussion started by: Trufla
4 Replies
Login or Register to Ask a Question