Sponsored Content
Top Forums Shell Programming and Scripting Replace special characters in multiple files - perl Post 302343383 by RMSoares on Wednesday 12th of August 2009 10:01:39 AM
Old 08-12-2009
Replace special characters in multiple files - perl

I have 100 files, where i want to search a set of strings and make the replacement by other strings

In the first case I want to include a parameter in the name of a file

LOG_DCT = $ LOG_DIR/DCT_GERAL_"$DATAINI".log
replace to : LOG_DCT = $ LOG_DIR / DCT_GERAL_ $ 1_ "$ DATAINI". log

I did tests with the instruction "perl -pi -e 's/DCT_GERAL/DCT_GERAL_ $ 1 /' filename”, but the result is not what we expected: LOG_DCT = $ LOG_DIR / DCT_GERAL__" $ DATAINI”.log replaces the $ 1 by null.


In the second case, I want to move the instruction of new line to the end of a printf

printf "\n# $IDCADEIA - $IDJOB - $HORAACTUAL - XPTO(YYYYMMDD)">> $ LOGFILE
Replace to: printf "$IDCADEIA - $IDJOB - $HORAACTUAL - XPTO(YYYYMMDD) \n#">> $ LOGFILE

I tried using the command "perl -pi -e 's/printf "\n#/printf "/' filename” and "perl -pi -e' s/) ">> $ LOGFILE /) \n#"> > $ LOGFILE/' filename”, but since the string has special characters ( ), \ ", #) it gives an error in the replacement.

Accepted suggestions of how to make these changes to files without having to have them manually: Smilie

regards
Rui
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replace Special characters in a file

Hi, I have a data like this in a file, 402003279034002000100147626030003300010000000000002000029000000 ær^M^\MÍW^H I need to replace those special char to some other char like # or $ Is there any ways to do it... I tried commands tr,sed and many but it was not able to replace because... (1 Reply)
Discussion started by: solai
1 Replies

2. Shell Programming and Scripting

Single/Multiple Line with Special characters - Find & Replace in Unix Script

Hi, I am creating a script to do a find and replace single/multiple lines in a file with any number of lines. I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE print $FIND gives Hi How r $u Rahul() Note:... (0 Replies)
Discussion started by: r_sarnayak
0 Replies

3. Shell Programming and Scripting

Using sed to replace special characters

Hi everyone I have file1 contains: '7832' ' 8765 6543 I want a sed command that will format as: '7832' , '8765' , '6543' I tried sed -e s/\'//g -e 's/^*//;s/*$//' file1 > file2 sed -e :a -e '$!N; s/\n/ /; ta' file2 which gives: 7832 8765 6543 I need some help to continue with... (5 Replies)
Discussion started by: nimo
5 Replies

4. Solaris

How to replace special characters in vi?

Hi , I want to replace the special characters in the file. For eg: cat abc 1234/4455/acb 234/k/lll/ 234`fs`fd I want to replace / and ` with the letter a and the output should like below. How to achieve this. 1234a4455aacb 234akallla 234afsafd (2 Replies)
Discussion started by: rogerben
2 Replies

5. Shell Programming and Scripting

Replace special characters

I have a line ending with special character and 0 The special character is the field separator for this line in VI mode the file will look like below, but while cat the special character wont display i know the hexa code for the special character ^_ is \x1f and ascii code is \0037, ... (0 Replies)
Discussion started by: ratheeshjulk
0 Replies

6. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

7. Shell Programming and Scripting

How to replace special characters?

Hi Unix Guru, I have an requirement for replace some specail characters in a file, my file came from mainframe. please see below example: when open it with vi 17896660|89059215|04/24/1998 00:00:00.000000| abc 123-453-1312^M<85>^M<85>|124557 if I run cat -v I got following:... (25 Replies)
Discussion started by: ken002
25 Replies

8. Shell Programming and Scripting

Help to replace the string with special characters

{"name":"alR_pl-ENVIRONMENT_192_168_211_123_sDK_PROVISION_7","description":"aLR_pl-ENVIRONMENT_192_168_211_123_sDK_PROVISION_7","json_class":"Chef::Role","default_attributes":{},"override_attributes":{"yoapp":{"jboss":"5.1.0","port":"2243","warname":"soap","datacenter":"alR","ip":"192.168.211.123","... (3 Replies)
Discussion started by: nikhil jain
3 Replies

9. UNIX for Advanced & Expert Users

How to replace special characters?

Hi Team, I have data like this. |*|.5|*|0.2|*|A.B|*| Would like to add zero (0) before the decimal point where there is no zero as |*|0.5|*|0.2|*|A.B|*| How to replace |*|. with |*|0. I tried below command which didn't work echo '|*|.5|*|0.2|*|A.B|*' | sed... (4 Replies)
Discussion started by: Ravi.K
4 Replies

10. UNIX for Beginners Questions & Answers

Replace Pattern with another that has Special Characters

Hello Team, Any help would be much appreciated for the below scenario: I have a sed command below where I am trying to replace the contents of 'old_pkey' variable with 'new_pkey' variable in a Soap request file (delete_request.txt). This works fine for regular string values, but this new_pkey... (8 Replies)
Discussion started by: ChicagoBlues
8 Replies
Config::PropertyConfigurator(3) 			User Contributed Perl Documentation			   Config::PropertyConfigurator(3)

NAME
Log::Log4perl::Config::PropertyConfigurator - reads properties file SYNOPSIS
# This class is used internally by Log::Log4perl use Log::Log4perl::Config::PropertyConfigurator; my $conf = Log::Log4perl::Config::PropertyConfigurator->new(); $conf->file("l4p.conf"); $conf->parse(); # will die() on error my $value = $conf->value("log4perl.appender.LOGFILE.filename"); if(defined $value) { printf("The appender's file name is $value "); } else { printf("The appender's file name is not defined. "); } DESCRIPTION
Initializes log4perl from a properties file, stuff like log4j.category.a.b.c.d = WARN, A1 log4j.category.a.b = INFO, A1 It also understands variable substitution, the following configuration is equivalent to the previous one: settings = WARN, A1 log4j.category.a.b.c.d = ${settings} log4j.category.a.b = INFO, A1 SEE ALSO
Log::Log4perl::Config Log::Log4perl::Config::BaseConfigurator Log::Log4perl::Config::DOMConfigurator Log::Log4perl::Config::LDAPConfigurator (tbd!) COPYRIGHT AND LICENSE
Copyright 2002-2009 by Mike Schilli <m@perlmeister.com> and Kevin Goess <cpan@goess.org>. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.1 2010-02-07 Config::PropertyConfigurator(3)
All times are GMT -4. The time now is 12:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy