Change a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change a string
# 1  
Old 12-15-2007
Change a string

I have my.cnf file:

[mysqld]
log-bin = mysql-bin
relay-log = relay-bin
#skip-slave-start
......

If there is no "skip-slave-start", I want to add it.
Or uncomment if it presents and commented.
Could someone tell me how to implement this feature in the easiest way?
# 2  
Old 12-17-2007
try this shell script:
Code:
#!/bin/bash
grep '^skip-slave-start' my.cnf >& /dev/null
if [ $? -ne 0 ] ; then
    echo "skip-slave-start is not turned on, so going to turn it on..."
    grep '^ *# *skip-slave-start' my.cnf >& /dev/null
    if [ $? -eq 0 ] ; then
    # skip-slave-start is commented
        sed -i 's/^ *# *skip-slave-start/skip-slave-start/' my.cnf
            # so uncommnt it
    else
    # skip-slave-start is not present
        sed -i 's/\[mysqld\]/[mysqld]\nskip-level-start/' my.cnf
            # so add it in [mysqld] section
    fi
else
    echo "skip-slave-start was turned on"
fi

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 to change tokenized string case

I'm trying to change the string cases for a particular column, but can't figure how do to it with sed. Example: Strings (space as delimiter): write group MYGROUP MySpecialGroup /local/users/mygroup write group HISGROUP HisSpecialGroup /local/users/hisgroup write group HerGroup... (3 Replies)
Discussion started by: fluffy_ko
3 Replies

2. UNIX for Dummies Questions & Answers

How do i change string in a certain column number?

I have a file which looks like this 01081023442 220000000410629994812279000001099952504280000000000000000000000000010050000000000 0000000000 0000000000 1101211221099952504280000010704525042800120000000000000000000000000000000000001 0000000000000006000000000000815500000010000010000000000000... (2 Replies)
Discussion started by: reignangel2003
2 Replies

3. Shell Programming and Scripting

change each letter of a string

Is there a way to change each letter of a string to the next one in the alphabet, so that a becomes b and f becomes g, and digits become one unit bigger - 4 becomes 5 and 9 becomes 0. I want to change strings like ben123 to cfo234. (5 Replies)
Discussion started by: locoroco
5 Replies

4. Shell Programming and Scripting

How to change last character in string with a variable value.

Hey Guys, I have text such as this. 28003,ALCORN,2 28009,BENTON,2 28013,CALHOUN,2 28017,CHICKASAW,2 47017,CARROLL,2 05021,CLAY,0 The last digit after the final "," is a variable value. This is the base file. I have to do further execution on this file later and I need to update the... (7 Replies)
Discussion started by: chagan02
7 Replies

5. Shell Programming and Scripting

[Perl] Find one string, change another string.

Hi, In principle I am searching for a Perl equivalent for this sed command: sed "/TIM_AM_ARGS=/ s/60/1440/" $EDIT_FILE > $TEMP_FILE cp $TEMP_FILE $EDIT_FILE I was wondering if it needs to be like this, or that there other, shorter, alternatives: open (TIMENVFILE, "<$timenvfile") or die... (5 Replies)
Discussion started by: ejdv
5 Replies

6. UNIX for Dummies Questions & Answers

How to change the order of a string ?

Hi , I want to change the order of a string using sed command . Is it possible ? $echo "abc123xyz" | sed 's/\()*\) \(*\)/\2\1/' abc123xyz $ echo "abc123xyz" |sed 's/\()*\) \(*\) \()*\)/\2\1\3/' abc123xyz I want to change the string , abc123xyz as xyz123abc . Is it... (5 Replies)
Discussion started by: rajavu
5 Replies

7. Shell Programming and Scripting

change of a string in different lines

hello, i have a dynamic file, which is generated by an ORACLE tool. Now i want to change a string, which begins with TABLESPACE following by "Name of Tablespace". The name of the new TABLESPACE is static. Example: TABLESPACE new : APPLI old: TABLESPACE "AMITTEL" new: TABLESPACE "APPLI" ... (4 Replies)
Discussion started by: bora99
4 Replies

8. Shell Programming and Scripting

change string in file

i have a file as input. file $1,$2,$3 $1,$2,$3 ( $ are string ) i want to grep $fail in $1 list if $1 = $fail i want to print $var in $3 the output file ( if $1=$fail in the third line) file1 $1,$2,$3 $1,$2,$3 $1,$2,$var (1 Reply)
Discussion started by: kamel.seg
1 Replies

9. Shell Programming and Scripting

How to change only the x first characters of a string?

Hi, How can I replace x first characters from a string? I have a file with... say 10000 entries as follows: 00123456781 00123456782 00123456783 ... What I want to do is change the leading "00" with for example "12" The leading 00 can be in some files some other 1 or more digits e.g.... (2 Replies)
Discussion started by: Juha
2 Replies

10. Shell Programming and Scripting

Change the a string in the file

Hi experts, If i have a directory and 10 files in it, which has string "Myapp" and i wish to change it to "Mydb" in all of the 10 files, how do i do that ? Thanks very much Regards G (3 Replies)
Discussion started by: kamathg
3 Replies
Login or Register to Ask a Question