Editing & Saving using shell script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Editing & Saving using shell script
# 1  
Old 03-23-2009
Editing & Saving using shell script

Hi,
OS: Unix, linux, hp-unix (all unix flavours)

Iam trying to change some string values, special characters or otherwise in a file. As of now, i go using vi <filename>, open the file and do the edit manually and save it.
Is it possible to write a shell script so that i just run the script which inturn opens this particular file and changes all the stuff needed and save the same.
The string values will be in any line in the file.

In file change.sh (I have to change three things as mentioned below)

** change database ****

From
Code:
connect to F750PAX

To
Code:
connect to F750PBX

*** Change of path ***

From
Code:
../jre/lpp/java/J1.4.2/bin/java com.telex.pt.environment.agent.Agent $1

To
Code:
/usr/lpp/java/IBM/J1.4.2/bin/java com.telex.pt.environment.agent.Agent $1

** Change of site name and port number ****

From
Code:
hubURL=http://clist.check.com:80/PSEMHUB/hub

To
Code:
hubURL=http://register.lagoon.com:8001/PSEMHUB/hub

I suppose its possible, but iam looking for some lead from you folks. Also i would like to replicate this in windows environment by writing bat scripts (It does the same job as in unix - by changing values in saving file). In windows there is some testing tool which can be used. But iam only looking into through bat scripts and not using any tools.

Anyway this forum is apart from windows. (Can anyone give me the windows bat script blog/forum link?).

So i would appreciate if anyone case get me on the unix enivronment.

thanks for your time.

Last edited by Yogesh Sawant; 03-25-2009 at 03:31 AM.. Reason: added code tags
# 2  
Old 03-24-2009
Try...
Code:
perl -pi -e '
s|connect to F750PAX|connect to F750PBX|g;
s|../jre/lpp/java/J1.4.2/bin/java com.telex.pt.environment.agent.Agent $1|/usr/lpp/java/IBM/J1.4.2/bin/java com.telex.pt.environment.agent.Agent $1|g;
s|hubURL=http://clist.check.com:80/PSEMHUB/hub|hubURL=http://register.lagoon.com:8001/PSEMHUB/hub|g' filename

# 3  
Old 03-24-2009
Oh. Thanks. Its as simple as that, which i dont know.
BTW, i understand you have used perl. I dont think i have perl installed in my box. How do i check if perl is installed?
Iam yet to know 'perl'.
Can i put this (your code) into my shell script and run the same?

thanks once again for your response.
# 4  
Old 03-24-2009
Thanks.
I found out from another thread "how to check that perl is installed on the system". That's perl -v
and checking my box, i do see perl is installed.
# 5  
Old 03-24-2009
Thanks once again. I put it in a shell script and its working perfectly.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

Font Editing to be done in shell script

Hi, Iam writing a script in unix shell and need to edit the output (With colors and bold/italic/underline) and send as email. Can someone please help me on this requirement Output as below. Need to know how to set this in echo command Message Flow: messageflow1 //need to put this in red... (7 Replies)
Discussion started by: Anusha M
7 Replies

3. Shell Programming and Scripting

Editing a file and saving it

HI I have a file samp1.xml which has the following content <ErrorMessage><ExceptionNumber>5117</ExceptionNumber><OriginalMessage><!<?xml version="1.0" encoding="UTF-8"?> <EMAILS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNameSpaceSchemaLocation=".\SMTPSchema.xsd"> <EMAIL... (7 Replies)
Discussion started by: harimhkr
7 Replies

4. Shell Programming and Scripting

shell script for saving oracle database records in variable

i want to retrieve value in each column of each row in sql plus and save them into array variable and echo the value in array variable (2 Replies)
Discussion started by: ramish
2 Replies

5. Shell Programming and Scripting

editing a file using shell script

HI all, I have file in the below format 1111111111_222222222_3333333 111111_22222_33333 11111111_222222_33333333333 i need to display this file like this 2222222_1111111111 22222_11111111 22222222222_1111111111111 can anyone help me with this Thanks in advance (1 Reply)
Discussion started by: saravanan71184
1 Replies

6. Shell Programming and Scripting

editing excel file through shell script

Hi, I am having a business file in excel having charts based on data already present on it. I would like to add new rows after the existing data and refesh the chart on it using shell script. For example-- In excel file in "sheet1", There is some data in first 10 rows ( from column A to F).... (0 Replies)
Discussion started by: sanjay1979
0 Replies

7. UNIX for Dummies Questions & Answers

Editing Shell Script

Hi I'm a newbie, but I understand that there's some space difference between unix and the pc, which is why I can't write shell script on my pc but I can view it using notepad, wordpad, etc. Is there any program I can use that will let me view the shell script and edit it without screwing up... (6 Replies)
Discussion started by: qtip
6 Replies

8. Shell Programming and Scripting

dynamic editing using shell script

Hi, I would like to edit an input data-file by changing a variable in it in steps: For ex: If my input file is 'big.in', then it has the following data: 2.54 0.01 0.5 0.0 My source code then reads this above line, executes and gives out some output. Then , I want to increment... (1 Reply)
Discussion started by: habzone2007
1 Replies

9. Shell Programming and Scripting

editing a file via a shell script ??

Morning All: I know this might be easy but since I don't do this very often I get stumped real quick... Sun box Solaris 8 ksh... I need to edit a file via a shell script. In this file I need to locate one specific line and then remove that line plus the next 20 line below that.... Any... (2 Replies)
Discussion started by: jimmyc
2 Replies

10. UNIX for Dummies Questions & Answers

Editing a file in a shell script

Using Solaris 8. I need to create a shell script that will edit a text file. I need to look in the text file and do a search and replace. For instance, the text file name is always 'filename'. I need to open filename and replace every instance of 'oldtext' with 'newtext'. 'oldtext' is static. ... (3 Replies)
Discussion started by: jowpup
3 Replies
Login or Register to Ask a Question