Solved

edit file in script

Posted on 2011-09-05
6
246 Views
Last Modified: 2012-05-12
Hello,

i have a config file that i want to change one line in. I would like to comment out the line, cpoy it and make one change to it. If that's too awkward I might just edit the line

Here is a sample of what the file is
...
....
OUT   FILE    VALUE=/usr/sbin/test_me
...
OUT  FILE2 VALUE=/usr/sbin/test_me2
,,,

I want to replace the line with FILE2 to become

OUT FILE2 VALUE=/usr/sbin/test_newvalue

I have to do this in many files so I need to be able to script ot
0
Comment
Question by:lolaferrari
  • 5
6 Comments
 
LVL 21

Expert Comment

by:Papertrip
ID: 36485629
pod@box:~$ cat testfile
OUT     FILE    VALUE=/usr/sbin/test_me
OUT     FILE2   VALUE=/usr/sbin/test_me2
pod@box:~$ perl -i -pe 'if ( $_ =~ /FILE2/ ) { s/test_me2/test_newvalue/ }' testfile
pod@box:~$ cat testfile
OUT     FILE    VALUE=/usr/sbin/test_me
OUT     FILE2   VALUE=/usr/sbin/test_newvalue

Open in new window


If you know the paths to the files, put them in a file and use a for loop.

pod@box:~$ for i in `cat list`; do perl -i -pe 'if ( $_ =~ /FILE2/ ) { s/test_me2/test_newvalue/ }' $i; done

Open in new window

0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36485680
I would like to comment out the line, cpoy it and make one change to it. If that's too awkward I might just edit the line

Apologies I overlooked the first part and just went straight to the edit.
0
 
LVL 21

Accepted Solution

by:
Papertrip earned 500 total points
ID: 36500266
@lolaferrari

Does that solution work for you?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:Papertrip
ID: 36520753
@lola, were you able to try this out?
0
 

Author Closing Comment

by:lolaferrari
ID: 36546477
many thanks - you don't happen to have a ksh or bash solution do you?
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36546679
Yes, execute that line of perl within your ksh/bash script ;)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
netstat -a in AIX unix 8 52
Tracking which app / process changes permission of a file in SOlaris 10 4 133
How to Insert a File Using Text Editor 9 102
Access_log 17 165
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question