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:
regards
Rui
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
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
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
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
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
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
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
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
{"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
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
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
STRINGS(1) General Commands Manual STRINGS(1)
NAME
strings - find the printable strings in a object, or other binary, file
SYNOPSIS
strings [ - ] [ -a ] [ -o ] [ -t format ] [ -number ] [ -n number ] [--] [file ...]
DESCRIPTION
Strings looks for ASCII strings in a binary file or standard input. Strings is useful for identifying random object files and many other
things. A string is any sequence of 4 (the default) or more printing characters ending with a newline or a null. Unless the - flag is
given, strings looks in all sections of the object files except the (__TEXT,__text) section. If no files are specified standard input is
read.
The file arguments may be of the form libx.a(foo.o), to request information about only that object file and not the entire library. (Typ-
ically this argument must be quoted, ``libx.a(foo.o)'', to get it past the shell.)
The options to strings(1) are:
-a This option causes strings to look for strings in all sections of the object file (including the (__TEXT,__text) section.
- This option causes strings to look for strings in all bytes of the files (the default for non-object files).
-- This option causes strings to treat all the following arguments as files.
-o Preceded each string by its offset in the file (in decimal).
-t format
Write each string preceded by its byte offset from the start of the file. The format shall be dependent on the single character
used as the format option-argument:
d The offset shall be written in decimal.
o The offset shall be written in octal.
x The offset shall be written in hexadecimal.
-number
The decimal number is used as the minimum string length rather than the default of 4.
-n number
Specify the minimum string length, where the number argument is a positive decimal integer. The default shall be 4.
-arch arch_type
Specifies the architecture, arch_type, of the file for strings(1) to operate on when the file is a universal file. (See arch(3) for
the currently know arch_types.) The arch_type can be "all" to operate on all architectures in the file, which is the default.
SEE ALSO
od(1)
BUGS
The algorithm for identifying strings is extremely primitive.
Apple Computer, Inc. September 11, 2006 STRINGS(1)