LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-11-2011, 10:18 AM   #1
dnoob
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Rep: Reputation: 0
sed does not remove word done from within shell script


I am trying to create a script to remove all instances of the word done from within my script. then cat a text file with the word done in it to append the word done at the end of my script so the while loop terminates properly


sed -i "s/done/ /g" /home/dnoob/script

cat text >> /home/dnoob/script

this does append the word done however
after i run the script the sed commands removes
the word done from within the sed command only

sed -i "s/ / /g"

what is wrong with my syntax here

I have tried single qoutes and back slash
 
Old 02-11-2011, 10:28 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
From within what sed command? Is there one in the file?

You may need to explain further.
 
Old 02-11-2011, 11:15 AM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hi,

is the 'sed' command inside your script that you want to modify??
Please post your script.
Another issue: You do not need to cat the word done from another text file. You can do this with sed:
Code:
sed -i 's/done/ /g;$ a done' /path/to/file
 
Old 02-11-2011, 11:49 AM   #4
dnoob
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Original Poster
Rep: Reputation: 0
here is the code


sed -i "s/ / /g" /home/dnoob/Desktop/scripts/shell.sh
cat dnoob >> /home/dnoob/Desktop/scripts/shell.sh

loop=y

while [ "$loop" = y ] ; do
echo "what does baket mean:" ; read word
if [ "$word" = why ]
then
echo "that is correct"
else
echo "that is not correct"
fi
echo "press (y) to continue (n) to quit" ; read loop
clear

if [ "$loop" = y ]
then

echo "what does maganda mean" ; read word
if [ "$word" = pretty ]
then
echo "good job"
else
echo "that is not correct"
fi
echo "(y) to continue (n) to terminate" ; read loop
clear
fi



if [ "$loop" = y ]
then

echo "what does pogi mean" ; read word
if [ "$word" = handsome ]
then
echo "good job"
else
echo "that is not correct"
fi
echo "(y) to continue (n) to terminate" ; read loop
clear
fi


done
done

Last edited by dnoob; 02-11-2011 at 05:13 PM.
 
Old 02-11-2011, 12:02 PM   #5
dnoob
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Original Poster
Rep: Reputation: 0
crts

the sed commnans works the first time i run it sed -i 's/done/ /g;$ a done' /path/to/file
when i look at the script after i run it the word done disappears
sed -i 's/ / /g;$ a '
 
Old 02-11-2011, 01:05 PM   #6
dnoob
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Original Poster
Rep: Reputation: 0
the sed command is inside my script
 
Old 02-11-2011, 01:19 PM   #7
normf
LQ Newbie
 
Registered: Jan 2005
Location: Luton
Distribution: Ubuntu 5.10 (Breezy Badger)
Posts: 10

Rep: Reputation: 0
Can you explain what it is you are trying to achieve in this script?
 
Old 02-11-2011, 02:26 PM   #8
dnoob
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Original Poster
Rep: Reputation: 0
the purpose of this script is two fold 1 test me in tagalog. 2 is to help me learn shell programming. this is a project i have created for myself once i complete this one i will move on to my next project.
 
Old 02-11-2011, 03:51 PM   #9
dnoob
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Original Poster
Rep: Reputation: 0
thank you for the assistance i got it
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file word by word part 2 justina Programming 7 01-25-2011 01:19 PM
How can i read two files word by word at a time using any loop by shell script? vaibhavs17 Programming 16 03-19-2010 03:48 AM
word by word comparison in two files using loop in shell script vaibhavs17 Programming 2 03-05-2010 07:41 AM
[SOLVED] Remove exact matching word using sed kushalkoolwal Programming 2 08-20-2009 05:15 PM
using sed to remove word wrap Harpune Linux - Software 2 03-02-2009 06:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration