making the changes permanent in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting making the changes permanent in a file
# 1  
Old 05-22-2007
CPU & Memory making the changes permanent in a file

Hi Friends.
I have a file called install.data which has fields like :

XXXXX
ACVCGFFTFY UAHIUH OI
CONNECTION=tape/11/
LOCATAION=08-90-89
SIZE=90

I had to change the values of some of these variables. So i did :
grep "SIZE" instal.data | sed 's/[0-9]*/00/' ...this is working fine on command line but i want to make this change permanent in the file without redirecting it to
other file .I dont want to make the changes in the Vi editor . I need to use some command . Can you help in this ???

Thanks,
Vijayaa
# 2  
Old 05-22-2007
My suggestion would be to have your sed command in a script and have it output to a temp file and then have the mv command write the temp file over the original file.
# 3  
Old 05-22-2007
If perl is available on your system, you can do something like that :
Code:
perl -p -i -e '/SIZE/ and s/[0-0]*/00/'  instal.data

Jean-Pierre.
# 4  
Old 05-22-2007
Hi,
This is a sample script incase you need to run on single or multiple files in a directory.

Code:
#!/bin/ksh
for file in *.txt ; do  
  sed  's/SIZE=[0-9][0-9]*/SIZE=00/g' $file > /tmp/${file}.new;   
  mv ${file} ${file}.old #Taking a backup before overwriting
  mv /tmp/${file}.new $file;
done

Thanks
Nagarajan Ganesan.
# 5  
Old 05-22-2007
if thats GNU sed, use the -i option
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Permanent file permissions within a directory

Hi All, I have an ftp process that is connecting to a Solaris server and pushing files into a directory. The default file permissions are rw-r--r-- . I want the file permissions to be rw-rw-r--. How can I configure the directory so any file created there will have the permissions... (6 Replies)
Discussion started by: rob4732
6 Replies

2. Shell Programming and Scripting

Making Changes to large file in vi

so i have a large file that has many lines in it. i want to make changes (replace certain things) that are in a range of lines, but NOT the whole file. how do i do this? say for instance, if i want to change all the occurrences of the word "ramamama" to "ram cow welcome" in lines 9333 to... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. UNIX for Dummies Questions & Answers

Making replicates of a file with part of a line randomized for each file

Ok, so let's say that I have a file like the following: I want to create 100 replicates of this file, except that for each file, I want different randomized combinations of either A or B at the end of each line so that I would end up with files like the following: and etc. I... (1 Reply)
Discussion started by: Scatterbrain26
1 Replies

4. UNIX for Dummies Questions & Answers

Making file executable

Hi guys, i'm trying to make a file called 'run-all-tests' executable but it is not letting me for some reason. I am presented with the following error: chmod: cannot access `./run-tests': No such file or directory Basically i have a folder called ex3 and within that there are task folders:... (11 Replies)
Discussion started by: Shyamz1
11 Replies

5. UNIX for Dummies Questions & Answers

permanent change in file

Hi! i want to replace ; by ok in a file as below test1(filename) containt:- Hi i am kaushlesh; i am new to Unix. i want permanent change in the file like below:- Hi i am kaushlesh ok i am new to unix How i will complite this..? (2 Replies)
Discussion started by: kaushelsh168
2 Replies

6. Solaris

ifconfig - making netmask & broadcast address permanent?

hi, I am trying to configure one of my interfaces, but after reboot - i lose the changes to the netmask & broadcast address. I have added an entry in /etc/netmasks, but it doesnt pick up the new settings. any ideas - much appreciated. before reboot: eri0:... (3 Replies)
Discussion started by: badoshi
3 Replies

7. UNIX for Dummies Questions & Answers

Making an alias permanent

Hi mates, I want to make an alias permanent for a KShell, does someone knows how to do that? Thanks! (4 Replies)
Discussion started by: agasamapetilon
4 Replies

8. AIX

Making Executable File

Hi All: I am a newbie. I have shell script and bunch of java jar files and I want to give one single executable file (may be .bin). Ex: I have test.sh, jar1.jar, jar2.jar. I have to make process.xxx When we run "process.xxx" it will run the "test.sh" script which inturn uses jar1.jar and... (0 Replies)
Discussion started by: laxman123
0 Replies

9. UNIX for Advanced & Expert Users

Permanent file deletion - sensitive data

All, I'm hoping someone can help fill me in on this one. :confused: I work with bank data deemed "sensitive" and, once processed, need to figure out a way to overwrite the files with enough garbage data in order to prevent someone from being able to recover any of the data from the disk. I... (5 Replies)
Discussion started by: peteroc
5 Replies

10. Shell Programming and Scripting

Making Changes without opening file

Hello, I'm new to scripting, I have a file test.dat. I want to make changes to it with out openning it. Example: test.dat has rows, and I want to change value "LA" to "TX" without opening it or without writing it to another file. Is it possible? Thanks (9 Replies)
Discussion started by: irehman
9 Replies
Login or Register to Ask a Question