updating a single line by script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting updating a single line by script
# 1  
Old 10-18-2010
Error updating a single line by script

hi,
I'm trying to add a # to the beginning of the line where the a word is included.

and the i want to run the whole original script.

and if possible I would prefer that line would stay in the same order in the text file, the line which includes the word.

Thanks,
# 2  
Old 10-18-2010
sed 's/.*word/#&/'
# 3  
Old 10-18-2010
Error

Thank you,

I am really new at shell scripting.

However I have a little problem when I do this.

Lets say that my original script is as follows;

#!/bin/ksh
echo "a"
echo "b"
echo "c"


and the update script;

#!/bin/ksh
sed 's/.*b/#&/' original.sh
./original.sh


the result i obtain is as follows;

#!/bin/ksh
echo "a"
#echo"b"
echo "c"


and the original.sh is not updated

how can i update original.sh or how can i see the output as;

a
c
# 4  
Old 10-18-2010
Quote:
Originally Posted by ozum

#!/bin/ksh
echo "a"
echo "b"

#!/bin/ksh
sed 's/.*b/#&/' original.sh
./original.sh

the result i obtain is as follows;

#!/bin/ksh
echo "a"
#echo"b"
echo "c"

and the original.sh is not updated

how can i update original.sh or how can i see the output as;

a
c
If you only see the updated result on your screen (std out) then try this:

Code:
sed 's/.*b/#&/' original.sh > temprorary.sh
mv temprorary.sh original.sh

# 5  
Old 10-18-2010
mv original.sh old.sh
sed 's/.*b/#&/' old.sh >original.sh
chmod 755 original.sh
# 6  
Old 10-18-2010
MySQL

Thank you so much..
# 7  
Old 10-18-2010
You need the mode to make it actually executable, along with the #! first line.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Merge multi-lines into one single line using shell script or Linux command

Hi, Can anyone help me for merge the following multi-line log which beginning with a " and line ending with ": into one line. *****Original Log***** 087;2008-12-06;084403;"mc;;SYHLR6AP1D\LNZW;AD-703;1;12475;SYHLR6AP1B;1.1.1.1;0000000062;HGPDI:MSISDN=12345678,APNID=1,EQOSID=365;... (3 Replies)
Discussion started by: rajeshlinux2010
3 Replies

2. Shell Programming and Scripting

Updating value from new last line of tempfile

Heyas A variable within a loop doesnt get updated - eventhough the 'inputfile' changes. I have a tempfile ($TMP.playstatus), which contains this data: 0.11 M-A: 0.000 fd= 0 aq= 4KB vq= 0KB sq= 0B f=0/0 0.14 M-A: 0.000 fd= 0 aq= 4KB vq= 0KB sq= 0B f=0/0 ... (13 Replies)
Discussion started by: sea
13 Replies

3. Shell Programming and Scripting

Shell script - Replace just part of a single line in a file.....

Hey guy's.... I new here, But im working on a school project, and I am not really good at programming. In fact, this is the only programming class that I need because programming is not what I am majoring in. But I have everything done in this shell script except for this last part..... ... (9 Replies)
Discussion started by: hxdrummerxc
9 Replies

4. Shell Programming and Scripting

editing single line in html file in perl script

Hi Folks, It is regarding the perl scripting. I have an html file(many files) which contains the below line in the body tag. <body> <P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P> </body> Now I want to read that html file through perl... (3 Replies)
Discussion started by: giridhar276
3 Replies

5. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

6. Shell Programming and Scripting

Single/Multiple Line with Special characters - Find & Replace in Unix Script

Hi, I am creating a script to do a find and replace single/multiple lines in a file with any number of lines. I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE print $FIND gives Hi How r $u Rahul() Note:... (0 Replies)
Discussion started by: r_sarnayak
0 Replies

7. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

8. Shell Programming and Scripting

bash script execution with a variable in a single line

Let a script needs a variable to execute. For example if i run ./test.sh then it needs a variable as there is a <STDIN> in the script. I want to execute it as in command line. Let test.sh requires a variable name $number I want to execute it by >test number <enter> how is it possible? (1 Reply)
Discussion started by: shoeb
1 Replies

9. Shell Programming and Scripting

Script to add a single line to middle of text file.

I've got a configuration file that is filled with xml text statements for example: <...../> <...../> <...../> <data id="java-options" value="-server -Djava.security.policy..../> <...../> <...../> <...../> I want to write a korn shell script that will go to this specific line and add a... (2 Replies)
Discussion started by: progkcp
2 Replies

10. Shell Programming and Scripting

Script needs to be modified - Each 5 Rows to be joined in single line with comma (,)

Hi All, I'm using the following script to produce a result: #!/bin/sh awk ' $0 ~ /\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+Interface\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+/ { match_str="YES"; line_cnt=0; next; } { if((line_cnt < 5) && ( match_str=="YES")) { print $0; line_cnt += 1; } else... (0 Replies)
Discussion started by: ntgobinath
0 Replies
Login or Register to Ask a Question