Sponsored Content
Top Forums Shell Programming and Scripting Edit a config file using shell script Post 302191133 by rajeshomallur on Thursday 1st of May 2008 03:48:55 PM
Old 05-01-2008
Quote:
Originally Posted by chappidi_pradee
hope this hepls you

sed -e 's/\(key1\=\)\(Old\)\(value1\)/\1New\2/g' filename

please iterate this in you shell programs for the key1 values and old value for each file.
Thanks pradee.

Will this work for the below cases?

#This is a comment. YesNoFlag = No means it will not print
YesNoFlag = No

And I need to change No to Yes
 

10 More Discussions You Might Find Interesting

1. AIX

How to edit txt file by shell script?

What I want to do is just delete some lines from a text file, I know it's easy using copy and redirect function, but what I have to do is edit this file (delete the lines) directly, as new lines may be added to the text file during this period. Can AIX do this ? # cat text 1:line1 2:line2... (3 Replies)
Discussion started by: dupeng
3 Replies

2. Shell Programming and Scripting

shell script to edit the content of a file

Hi I need some help using shell script to edit a file. My original file has the following format: /txt/email/myemail.txt /txt/email/myemail2.txt /pdf/email/myemail.pdf /pdf/email/myemail2.pdf /doc/email/myemail.doc /doc/email/myemail2.doc I need to read each line. If the path is... (3 Replies)
Discussion started by: tiger99
3 Replies

3. Shell Programming and Scripting

Edit hibernate config file

I'd like to use a shell script to edit the params in my hibernate.cfg.xml file. I need to substitute the database info(user name, password,url) Here is a look at it: <hibernate-configuration> <session-factory name=""> <property... (1 Reply)
Discussion started by: mc1392
1 Replies

4. Shell Programming and Scripting

How to edit particular cell of csv file using shell script

I have one csv file and in that I want update particular cell. I know the row and coloumn number for that respective. Please help me... (6 Replies)
Discussion started by: deepak_p86
6 Replies

5. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

6. Shell Programming and Scripting

Shell script to edit a file

Hello, I have a big file in wich I would like to rename inside this exactly the string '_ME' and not rename in case we have 'ABC_MELANGE'. Is there a way to do it by using a shell script? Any tip will be apreciated. The file is like described bellow, after using command more filename : ... (3 Replies)
Discussion started by: Titas
3 Replies

7. Shell Programming and Scripting

shell script to edit a file

i have a file called number which contains data as 1 2 3 4 5 6 7 8 9 0 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 needed a shell script to print the output as 1 7 7 1 4 and (2 Replies)
Discussion started by: jacky29
2 Replies

8. Shell Programming and Scripting

Automating using shell script : edit the file in a directory

I am trying to automate hadoop installation procedure using shell script. It involves go to perticular directory and add some more lines to the file /etc/sysctl.conf. How this can be done? Regards Navaz (1 Reply)
Discussion started by: Abdul Navaz
1 Replies

9. Homework & Coursework Questions

Edit the file in shell script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to automate hadoop installation procedure using shell script. It involves go to perticular directory... (3 Replies)
Discussion started by: Abdul Navaz
3 Replies

10. Shell Programming and Scripting

Open and edit a file using a shell script

Hello Folks, I have a file named as date.dat present at /tmp/abc location which has following data - 20161030,20161031,20161101 I need to remove this line and replace it with something like below - $param1,$param2,$param3 Param1, Param2 and param3 stores the date based on some calculation in... (1 Reply)
Discussion started by: ektubbe
1 Replies
DBM::Deep::Cookbook(3pm)				User Contributed Perl Documentation				  DBM::Deep::Cookbook(3pm)

NAME
DBM::Deep::Cookbook - Cookbook for DBM::Deep DESCRIPTION
This is the Cookbook for DBM::Deep. It contains useful tips and tricks, plus some examples of how to do common tasks. RECIPES
Unicode data If possible, it is highly recommended that you upgrade your database to version 2 (using the utils/upgrade_db.pl script in the CPAN distribution), in order to use Unicode. If your databases are still shared by perl installations with older DBM::Deep versions, you can use filters to encode strings on the fly: my $db = DBM::Deep->new( ... ); my $encode_sub = sub { my $s = shift; utf8::encode($s); $s }; my $decode_sub = sub { my $s = shift; utf8::decode($s); $s }; $db->set_filter( 'store_value' => $encode_sub ); $db->set_filter( 'fetch_value' => $decode_sub ); $db->set_filter( 'store_key' => $encode_sub ); $db->set_filter( 'fetch_key' => $decode_sub ); A previous version of this cookbook recommended using "binmode $db->_fh, ":utf8"", but that is not a good idea, as it could easily corrupt the database. Real-time Encryption Example NOTE: This is just an example of how to write a filter. This most definitely should NOT be taken as a proper way to write a filter that does encryption. (Furthermore, it fails to take Unicode into account.) Here is a working example that uses the Crypt::Blowfish module to do real-time encryption / decryption of keys & values with DBM::Deep Filters. Please visit <http://search.cpan.org/search?module=Crypt::Blowfish> for more on Crypt::Blowfish. You'll also need the Crypt::CBC module. use DBM::Deep; use Crypt::Blowfish; use Crypt::CBC; my $cipher = Crypt::CBC->new({ 'key' => 'my secret key', 'cipher' => 'Blowfish', 'iv' => '$KJh#(}q', 'regenerate_key' => 0, 'padding' => 'space', 'prepend_iv' => 0 }); my $db = DBM::Deep->new( file => "foo-encrypt.db", filter_store_key => &my_encrypt, filter_store_value => &my_encrypt, filter_fetch_key => &my_decrypt, filter_fetch_value => &my_decrypt, ); $db->{key1} = "value1"; $db->{key2} = "value2"; print "key1: " . $db->{key1} . " "; print "key2: " . $db->{key2} . " "; undef $db; exit; sub my_encrypt { return $cipher->encrypt( $_[0] ); } sub my_decrypt { return $cipher->decrypt( $_[0] ); } Real-time Compression Example Here is a working example that uses the Compress::Zlib module to do real-time compression / decompression of keys & values with DBM::Deep Filters. Please visit <http://search.cpan.org/search?module=Compress::Zlib> for more on Compress::Zlib. use DBM::Deep; use Compress::Zlib; my $db = DBM::Deep->new( file => "foo-compress.db", filter_store_key => &my_compress, filter_store_value => &my_compress, filter_fetch_key => &my_decompress, filter_fetch_value => &my_decompress, ); $db->{key1} = "value1"; $db->{key2} = "value2"; print "key1: " . $db->{key1} . " "; print "key2: " . $db->{key2} . " "; undef $db; exit; sub my_compress { my $s = shift; utf8::encode($s); return Compress::Zlib::memGzip( $s ) ; } sub my_decompress { my $s = Compress::Zlib::memGunzip( shift ) ; utf8::decode($s); return $s; } Note: Filtering of keys only applies to hashes. Array "keys" are actually numerical index numbers, and are not filtered. Custom Digest Algorithm DBM::Deep by default uses the Message Digest 5 (MD5) algorithm for hashing keys. However you can override this, and use another algorithm (such as SHA-256) or even write your own. But please note that DBM::Deep currently expects zero collisions, so your algorithm has to be perfect, so to speak. Collision detection may be introduced in a later version. You can specify a custom digest algorithm by passing it into the parameter list for new(), passing a reference to a subroutine as the 'digest' parameter, and the length of the algorithm's hashes (in bytes) as the 'hash_size' parameter. Here is a working example that uses a 256-bit hash from the Digest::SHA256 module. Please see <http://search.cpan.org/search?module=Digest::SHA256> for more information. The value passed to your digest function will be encoded as UTF-8 if the database is in version 2 format or higher. use DBM::Deep; use Digest::SHA256; my $context = Digest::SHA256::new(256); my $db = DBM::Deep->new( filename => "foo-sha.db", digest => &my_digest, hash_size => 32, ); $db->{key1} = "value1"; $db->{key2} = "value2"; print "key1: " . $db->{key1} . " "; print "key2: " . $db->{key2} . " "; undef $db; exit; sub my_digest { return substr( $context->hash($_[0]), 0, 32 ); } Note: Your returned digest strings must be EXACTLY the number of bytes you specify in the hash_size parameter (in this case 32). Undefined behavior will occur otherwise. Note: If you do choose to use a custom digest algorithm, you must set it every time you access this file. Otherwise, the default (MD5) will be used. PERFORMANCE
Because DBM::Deep is a conncurrent datastore, every change is flushed to disk immediately and every read goes to disk. This means that DBM::Deep functions at the speed of disk (generally 10-20ms) vs. the speed of RAM (generally 50-70ns), or at least 150-200x slower than the comparable in-memory datastructure in Perl. There are several techniques you can use to speed up how DBM::Deep functions. o Put it on a ramdisk The easiest and quickest mechanism to making DBM::Deep run faster is to create a ramdisk and locate the DBM::Deep file there. Doing this as an option may become a feature of DBM::Deep, assuming there is a good ramdisk wrapper on CPAN. o Work at the tightest level possible It is much faster to assign the level of your db that you are working with to an intermediate variable than to re-look it up every time. Thus # BAD while ( my ($k, $v) = each %{$db->{foo}{bar}{baz}} ) { ... } # GOOD my $x = $db->{foo}{bar}{baz}; while ( my ($k, $v) = each %$x ) { ... } o Make your file as tight as possible If you know that you are not going to use more than 65K in your database, consider using the "pack_size => 'small'" option. This will instruct DBM::Deep to use 16bit addresses, meaning that the seek times will be less. SEE ALSO
DBM::Deep(3), Digest::MD5(3), Digest::SHA256(3), Crypt::Blowfish(3), Compress::Zlib(3) perl v5.14.2 2012-06-24 DBM::Deep::Cookbook(3pm)
All times are GMT -4. The time now is 02:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy