Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

edit file in script

Posted on 2011-09-05
6
245 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

808 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