Asst: Shell Script to sed


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Asst: Shell Script to sed
# 8  
Old 12-08-2013
On the second line you could add a
Code:
set -x

statement. It may tell you some more...
# 9  
Old 12-09-2013
Code:
sh -x sub3 'l*' 'L' '_cat.dog.dat' 'home/bnaranjo/UnixCourse/scriptAsst/../_hippo.cpp'
+ p1=l*
+ shift
+ p2=L
+ shift
+ echo l*
l*
+ echo L
L
+ echo l*
+ sed -e s/\([*.[^$]]\)/\\\1/g
+ cat temp
+ p1=l*
+ rm temp
+ echo l*
l*
+ sed s/l*/L/g _cat.dog.dat
+ mv temp.out _cat.dog.dat
+ echo l*
l*
+ echo L
L
+ echo l*
+ sed -e s/\([*.[^$]]\)/\\\1/g
+ cat temp
+ p1=l*
+ rm temp
+ echo l*
l*
+ sed s/l*/L/g home/bnaranjo/UnixCourse/scriptAsst/../_hippo.cpp
sed: can't read home/bnaranjo/UnixCourse/scriptAsst/../_hippo.cpp: No such file or directory
+ mv temp.out home/bnaranjo/UnixCourse/scriptAsst/../_hippo.cpp
mv: cannot move `temp.out' to `home/bnaranjo/UnixCourse/scriptAsst/../_hippo.cpp': No such file or directory

Its not grabbing the /_hippo.cpp file on this test, how can i make it able to do that?
# 10  
Old 12-09-2013
Do you mean to use a relative path from your current directory and if so can your ls -l the file? Or do you mean to use
Code:
/home/bnaranjo/UnixCourse/scriptAsst/../_hippo.cpp

# 11  
Old 12-10-2013
Quote:
Originally Posted by Scrutinizer
Do you mean to use a relative path from your current directory and if so can your ls -l the file? Or do you mean to use
Code:
/home/bnaranjo/UnixCourse/scriptAsst/../_hippo.cpp

Yeah i need to use
Code:
home/bnaranjo/UnixCourse/scriptAsst ../_hippo.cpp

, its part of the script testing from what i now, thank you srutinizer

---------- Post updated at 11:30 PM ---------- Previous update was at 07:18 PM ----------

How would i use ls -l in the file?
# 12  
Old 12-10-2013
I mean on the command prompt, go to the directory where you call the script and then issue the command
Code:
ls -l home/bnaranjo/UnixCourse/scriptAsst/../_hippo.cpp

# 13  
Old 12-10-2013
Where does the home/bnaranjo/ come from?
From your teacher? Maybe it should be /home/bnaranjo/?
Do a cd / (where home and /home are the same) and run your script from there!
# 14  
Old 12-13-2013
Code:
#!/bin/sh
set -x
A="$1"
shift
B="$1"
shift

for FILE in "$@"
do
        echo $A
        echo $B
        echo "Process $FILE using $A and $B..."

        #echo "$A" | sed -e 's/\([*.[^$]\)/\\\1/g' > target
        #A="`cat target`"
        #rm target
        #echo $A

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

I got this but get an error.
Code:
37...
+ p1=l*
+ shift
+ p2=L
+ shift
+ echo l*
+ echo L
+ echo Process _cat.dog.dat using l* and L...
+ sed s/l*/L/g _cat.dog.dat
+ mv temp.out _cat.dog.dat
+ echo l*
+ echo L
+ echo Process /home/sofestafont/UnixCourse/scriptAsst/../_hippo.cpp using l* and L...
+ sed s/l*/L/g /home/sofestafont/UnixCourse/scriptAsst/../_hippo.cpp
+ mv temp.out /home/sofestafont/UnixCourse/scriptAsst/../_hippo.cpp

sub3 produced incorrect output on test 37: /home/sofestafont/UnixCourse/scriptAsst/sub3 'l*' 'L' '_cat.dog.dat' '/home/sofestafont/UnixCourse/scriptAsst/../_hippo.cpp'

Which looks like the regular expression got converted to plain text properly.
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; afgcxa.pem4jan.rain.nc afgcxa.pem4feb.rain.nc afgcxa.pem4mar.rain.nc afgcxa.pem4apr.rain.nc I want to rename them to afgcxa.pem4-01.jan.rain.nc afgcxa.pem4-02.feb.rain.nc afgcxa.pem4-03.mar.rain.nc ... (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