I need to add something to a file, plzz help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I need to add something to a file, plzz help
# 1  
Old 07-31-2008
I need to add something to a file, plzz help

The first step for you to create the script to change “JAVA_OPTS” variable definition as follows:

Original line:
JAVA_OPTS="-Dname=$JAVA_NAME -Xmx$JVM_MAX -DAGENT_HOME=$RT_HOME -DINSTALL_DIR=$RT_HOME -Djavax.net.ssl.keyStore=$RT_HOME/conf/client.keystore -Djavax.net.ssl.keyStoreType=jks -Djavax.net.ssl.keyStorePassword -Dhttps.cipherSuites=SSL_RSA_WITH_RC4_128_SHA $DEBUG_OPTS -COMM_NOT_DEPLOY=native_lib $AGENT_CONFIG_PROPS"

Change to:
JAVA_OPTS="-client -Dname=$JAVA_NAME -Xmx$JVM_MAX -DAGENT_HOME=$RT_HOME -DINSTALL_DIR=$RT_HOME -Djavax.net.ssl.keyStore=$RT_HOME/conf/client.keystore -Djavax.net.ssl.keyStoreType=jks -Djavax.net.ssl.keyStorePassword -Dhttps.cipherSuites=SSL_RSA_WITH_RC4_128_SHA $DEBUG_OPTS -COMM_NOT_DEPLOY=native_lib $AGENT_CONFIG_PROPS




IF THE "-client" option is already in, do nothing and print out the message " no change is needed" or add "-client" to the orignal script.


please reply me
thanks

# 2  
Old 07-31-2008
Sounds like homework...

A possible solution :
Code:
> cat asirohi.sh
InputFile='asirohi.dat'
JavaOpts='JAVA_OPTS'

if grep -q "^$JavaOpts=" $InputFile
then
   if grep -q "^$JavaOpts=\"-client " $InputFile
   then
      echo "No change neeeded !"
   else
      sed "s/^\($JavaOpts=\"\)/\1-client /" $InputFile > ${InputFile}.tmp && \
      mv ${InputFile}     ${InputFile}.old                                && \
      mv ${InputFile}.tmp ${InputFile}
   fi
else
   echo "File doesn't contain $JavaOpts variable definition !"
fi
> cat asirohi.dat
ROOT=/
JAVA_OPTS="-Dname=$JAVA_NAME -Xmx$JVM_MAX -DAGENT_HOME=$RT_HOME -DINSTALL_DIR=$RT_HOME -Djavax.net.ssl.keyStore=$RT_HOME/conf/client
.keystore -Djavax.net.ssl.keyStoreType=jks -Djavax.net.ssl.keyStorePassword -Dhttps.cipherSuites=SSL_RSA_WITH_RC4_128_SHA $DEBUG_OPT
S -COMM_NOT_DEPLOY=native_lib $AGENT_CONFIG_PROPS"
TMP=/tmp
> asirohi.sh
> cat asirohi.dat
ROOT=/
JAVA_OPTS="-client -Dname=$JAVA_NAME -Xmx$JVM_MAX -DAGENT_HOME=$RT_HOME -DINSTALL_DIR=$RT_HOME -Djavax.net.ssl.keyStore=$RT_HOME/con
f/client.keystore -Djavax.net.ssl.keyStoreType=jks -Djavax.net.ssl.keyStorePassword -Dhttps.cipherSuites=SSL_RSA_WITH_RC4_128_SHA $D
EBUG_OPTS -COMM_NOT_DEPLOY=native_lib $AGENT_CONFIG_PROPS"
TMP=/tmp
> asirohi.sh
No change neeeded !
> cat asirohi.dat
ROOT=/
JAVA_OPTS="-client -Dname=$JAVA_NAME -Xmx$JVM_MAX -DAGENT_HOME=$RT_HOME -DINSTALL_DIR=$RT_HOME -Djavax.net.ssl.keyStore=$RT_HOME/con
f/client.keystore -Djavax.net.ssl.keyStoreType=jks -Djavax.net.ssl.keyStorePassword -Dhttps.cipherSuites=SSL_RSA_WITH_RC4_128_SHA $D
EBUG_OPTS -COMM_NOT_DEPLOY=native_lib $AGENT_CONFIG_PROPS"
TMP=/tmp
~/Forums>

Jean-Pierre.
# 3  
Old 07-31-2008
how does this work, is there not a simple way to parse and add "-client" if its not present.
# 4  
Old 07-31-2008
Use sed:
Code:
sed 's/"-Dname/"-Client -Dname/g' file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I add a log file path to a vi file to monitor all the changes made to the file?

I'm curious to know how do I add an empty log file (test1.log) to an existing text file to monitor all the changes made to a.txt. Is this expression export PATH=$PATH:/home/test1.log right to be added to the text file a.txt? (5 Replies)
Discussion started by: TestKing
5 Replies

2. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

3. Homework & Coursework Questions

need help with a shel script plzz

hey how u doing guys ... I'm a student @ EMU and taking a beginner Linux class and I have those two extra credit project that im struggling with so I hope to get some correction and help write a shell script that will 1-prompt the user for a file name 2-check to see if the file exists... (2 Replies)
Discussion started by: flyman
2 Replies

4. Shell Programming and Scripting

Strange errors with shell scripts..plzz help

Hi all... Please help me with this questions. I am not good at shell scripting. 1) It seems like there are many ways that we can run the shell scripts. what is the difference between each one? i)./shell_script.sh ii).(space)./ shell_script.sh iii)sh shell_script.sh ... (3 Replies)
Discussion started by: sanskumar2003
3 Replies

5. Shell Programming and Scripting

Shell Script..plzz help

Hi all, if any body could help me out to automate the unix script for finding some particualar files which are based on dates like see every day i need check the TXT files which are being in processed and Sequential order based on dates For Example: files name starts at... (12 Replies)
Discussion started by: krux_rap
12 Replies

6. Shell Programming and Scripting

Not able to solve these questions plzz help

1.Display a list of /usr/share/doc subdirectories containing information about shells.How many README files do these subdirectories contain? Don't count anything in the form of "README.a_string". 2.Make a list of files in your home directory that were changed less that 10 hours ago, using grep,... (2 Replies)
Discussion started by: cynosure2009
2 Replies

7. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies

8. Shell Programming and Scripting

shell script & sqlplus "plzz help"

hi friends, i m tryin to load data from one set of table to other i have sql procedure al ready for it..! i m going to load the procedure only if data in one of my table for example table "landing " have 10 records each attribute of this table is file_name status date ... (2 Replies)
Discussion started by: kulbir
2 Replies

9. UNIX for Dummies Questions & Answers

problem with GREP, help plzz

I just want the output of this command to be stored in a variable like, str = `grep Application.dbName serverdata/ServerProp.txt` but while executing it says like, str : startup 11: not found, where startup is the script name. but while running the command alone like, grep... (2 Replies)
Discussion started by: cs_sakthi
2 Replies
Login or Register to Ask a Question