shell script for changing two text files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script for changing two text files
# 1  
Old 03-19-2010
shell script for changing two text files

HELLO
I am new in shell bash script>
I have two text files.They contain same datas.
I want to change some text in two files.If I changed in one file.Then I want to change another same file without using vieditor.Iwant to change another file by using shell script
for example
file1
hello
good morning
file2

hello
good morning

then i changed contents of file1 like this
hello
good evening
then i want to change file2the samechanges in file1 by using shellscript.
could you help me........

Last edited by vidhun.v; 03-19-2010 at 12:40 PM.. Reason: delete
# 2  
Old 03-19-2010
Question

Why not just copy file1 to file2?
# 3  
Old 03-19-2010
no.it is not good aways copy to one.I think you didn't understand my question.IF i change one text in a file1.Then i also want same change in file2.

---------- Post updated at 08:59 AM ---------- Previous update was at 08:48 AM ----------

Hello
I think you didn't understand my question.THe files are containing same text.But if Ichange one word in afile1,I want same change in file2.
# 4  
Old 03-19-2010
And why isn't copy a good Idea?

Another approach may be using SymLinks...
# 5  
Old 03-19-2010
Hello
It's ok.
have a look my files one is text file.
and another is shell file.
this is my shell file
!/bin/sh
cat>>DNS_Registry<<!
$TTL 3600
@ IN SOA ns2.isgroup.sr. admin.isgroup.sr. (
2012031701 ; Serial
10800 ; refresh after 3hours
3600 ; retry after 1 hour
604800 ; expire after a week
300 ; negative response TTL
)
;DNS Servers, NS, ns2.isgroup.sr.
; Mail servers, MX, 5mail
localhost,A, 10.2.2.4
;0-19 servers
tyra, A, 10.2.2.1
grace, A, 10.2.2.2
ariadne,A, 10.2.2.3
mail, A, 10.2.2.4
;ftp, A, 10.2.2.4
ldap, A, 10.2.2.4
ns2, A, 10.2.2.4
www, A, 10.2.2.4
!
If i execute this file i got the file DNS_Registry
Then I change something in DNS_Registry text file.Iwant to getthe same change in a shellfile
ex:IN a DNS_Registry file ichanged something like that
mail, A, 10.2.2.5
THEN I WANT THIS SAME CHANGE IN SHELL FILE.
SO I WANT SHELL SCRIPT
# 6  
Old 03-19-2010
Question

If you have
datafile1 = your registry data
then, cp datafile1 to datfile2
make your changes to datafile1
use a diff command to show before/after changes
then this could be used with a script to sed your changes in script

Does that logic make sense?
# 7  
Old 03-19-2010
Hi vidhun.v:

I imagine there's something preventing you from simply editing the shell script and executing it to regenerate the DNS_Registry file, instead of the other way around.

No offense, but this setup sounds like a mess. You have file A whose data is used to create file B which if changed must then be used to modify file A. The answer to this problem is probably stepping back and reengineering the solution at a higher level. Ideally, there should be one and only one authoritative source for the data. Editing is only done on this one source and all other files that make use of it either include it or are generated from it.

Good Luck,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help in comparing 2 text files in shell script

Hi All, I have 2 files like below vi f1 frog elephant rabit zebra dog vi f2 rabit dog ============== Now i want to comapre two files and the result will be frog (8 Replies)
Discussion started by: kumar85shiv
8 Replies

2. UNIX for Dummies Questions & Answers

Changing text in multiple files, but with different text for each file

Hello, I have a situation where I want to change a line of text in multiple files, but the problem is that I want to change the text to something unique for each file. For example, let's say I have five files named bob.txt, joe.txt, john.txt, tom.txt, and zach.txt. Each of these files has a... (5 Replies)
Discussion started by: Scatterbrain26
5 Replies

3. Shell Programming and Scripting

how to read two text files in the same shell script

Folks i have written two scripts that do reading of csv files , i am currently fetching the all part of the line in to variables and braking the line into several variables. I am doing the same thing in an another shell script, i want to integrate both the scripts in to a single one where i can... (2 Replies)
Discussion started by: venu
2 Replies

4. UNIX for Dummies Questions & Answers

Using Shell Script To Loop Program Through Multiple Text Files

Hello, So I have approximately 300 files of raw data (.txt) files that I am using to perform statistical analysis. I have been able to construct a Fortran program that is able to perform my statistical analysis on a file by file basis. However, I now want to be able to loop program through... (19 Replies)
Discussion started by: Jimmyd24
19 Replies

5. Shell Programming and Scripting

Removing matching text from multiple files with a shell script

Hello all, I am in need of assistance in creating a script that will remove a specified block of text from multiple .htaccess files. (roughly 1000 files) I am attempting to help with a project to clean up a linux server that has a series of unwanted url rewrites in place, as well as some... (4 Replies)
Discussion started by: boxx
4 Replies

6. Shell Programming and Scripting

Shell Script Needed to Read a text from a list files

Hi, Below is my issue which I desperately need and I want a shell script which can do this job. I need this script as I m planning to put this for a system health check. Please assist me. 1. There are 10 log files in a particular location. 2. open each log file. Goto to the end of the... (4 Replies)
Discussion started by: kashriram
4 Replies

7. Shell Programming and Scripting

Dynamically creating text files using shell script

Hi All, I want to create a shell script which dynamically create text files. i am using the following script $i=1 while do cat > test_$i.txt done but while running the script it was stopping(the cursor not going to next step, i have to enter ctrl+c to make it stop). it is creating only... (2 Replies)
Discussion started by: KiranKumarKarre
2 Replies

8. Shell Programming and Scripting

How to run cmds after changing to a new env (shell) in a shell script

Hi, I am using HP-UNIX. I have a requirement as below I have to change env twice like: cadenv <env> cadenv <env> ccm start -d /dbpath ccm tar -xvf *.tar ccm rcv .... mv *.tar BACKUP but after I do the first cadenv <env> , I am unable to execute any of the later commands . ... (6 Replies)
Discussion started by: charlei
6 Replies

9. UNIX for Dummies Questions & Answers

Changing korn shell script text Menu colors?

Is it possible to change the color of text in a korn shell script Menu? I can change the color of session text through my telnet client but I want to be able to change color text in the Korn shell menu to highlight certain items. (6 Replies)
Discussion started by: darthur
6 Replies
Login or Register to Ask a Question