Sponsored Content
Top Forums Shell Programming and Scripting Perl/sed Escape Syntax Problem . . . Post 302923756 by bartus11 on Tuesday 4th of November 2014 11:13:56 AM
Old 11-04-2014
You can also do something like this:
Code:
#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;

qx'sed -i "s/Hi Mom!\|Hi Dad!/Bye Everyone!/I" ./test.txt';

No more double backslash, but you have to change the quote character in the sed command.
This User Gave Thanks to bartus11 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

possible to escape the \ character in sed?

is it possible to escape the \ character in sed? right now I'm trying to replace all occurances of \ with \\ sed \"s|test|test_replacement|g\" file1 > output; #this works fine sed \"s|\\|\\\|g\" file1 > output; #this generates the following error: sed: -e expression #1, char 17:... (1 Reply)
Discussion started by: gammaman
1 Replies

2. Shell Programming and Scripting

Help for Sed Syntax problem

I have one File named "txt_file" # cat txt_file <DBType>RT</DBType> <AppType>RT</AppType> -------------------------------------------------- I want replace "<AppType>RT</AppType>" to <AppType>XY</AppType> in txt_file and output redirect to Newfile ... (2 Replies)
Discussion started by: SanjayLinux
2 Replies

3. Shell Programming and Scripting

Perl syntax for sed searches

I am aware that Perl has a lot of features that originally came from sed and awk. I have a pattern that I am using like this: sed -n '/|Y|/p' I want to do the same thing in Perl and be able to either save that value in some kind of variable or array or potentially write it out to a file. ... (11 Replies)
Discussion started by: masinick
11 Replies

4. Shell Programming and Scripting

Escape character - sed

Hi All, How do i write in sed for the 6th and 7th field of etc/passwd file as it involves "/" character? Does mine below is correct? It's incomplete script as i need help with syntax as i always getting may errors :( Example of etc/passwd file: blah:x:1055:600:blah... (6 Replies)
Discussion started by: c00kie88
6 Replies

5. Shell Programming and Scripting

SED: Replacing $1 with $2 escape problem

Hi all, I have a script which uses sed to replace one string with another. The problem is, the string to be matched, and its replacement are coming in as two command line arguments $1 and $2 $1 and $2 can be absolutely anything, but both should be treated purely as strings. My sed command... (7 Replies)
Discussion started by: mark007
7 Replies

6. Shell Programming and Scripting

perl how to escape (|) character

my @array; my $sepa = "|"; print $sepa; open FH, "<100_20091023_2.txt"; while(<FH>){ push @array, split(/\$sepa/, $_); print "@array\n\n"; } I am not able split the line which have | separated (1 Reply)
Discussion started by: pritish.sas
1 Replies

7. Shell Programming and Scripting

Problem with sed in perl!!

Hi, I am facing an issue with sed in perl. I have a file which has 2 header lines and one trailer line. I need to process the file without these headers and trailer. My file looks like : File.txt:- Header1 Header2 data1 data2 trailer For removing header and trailer from file I am using... (5 Replies)
Discussion started by: abhisharma23
5 Replies

8. Shell Programming and Scripting

Problem with using a sed to add escape character \ before $ and ' symbols

Hi all, I've got a problem with sed. Want to use it to add escape character \ before $ and ' symbols so condition='1'$some will become condition=\'1\'\$some echo "condition='1'$some" | sed 's/\($\)/\\\1/g' is not working properly. Can somebody help me with this please? Regards,... (7 Replies)
Discussion started by: johny_be_good
7 Replies

9. Shell Programming and Scripting

sed - with escape character

i have string as below str=".<date>" in which i need to replace < with /< , when i tried with sed , got the output. --> echo $str | sed 's/</\\</g' .\<date> when i tried to assign it to a variable , i am not getting the same --> a=`echo $str | sed 's/</\\</g'` ; echo $a... (4 Replies)
Discussion started by: expert
4 Replies

10. UNIX for Beginners Questions & Answers

How to escape % with sed?

Hello, I am running ubuntu 16.04 I searched "how to replace dot by % using sed" but no luck. file My.Name.Is.Earl Expected output My%Name%Is%Earl I tried: sed -i "s|.||g" file sed -i "s|.|{%}|g" file sed -i "s|.|\%|g" file I'd appreciate your help Thank you Boris (6 Replies)
Discussion started by: baris35
6 Replies
SHTOOL-SUBST.TMP(1)					      GNU Portable Shell Tool					       SHTOOL-SUBST.TMP(1)

NAME
shtool-subst - GNU shtool sed(1) substitution operations SYNOPSIS
shtool subst [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning] [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup ext] [-e|--exec cmd] [-f|--file cmd-file] [file] [file ...] DESCRIPTION
This command applies one or more sed(1) substitution operations to stdin or any number of files. OPTIONS
The following command line options are available. -v, --verbose Display some processing information. -t, --trace Enable the output of the essential shell commands which are executed. -n, --nop No operation mode. Actual execution of the essential shell commands which would be executed is suppressed. -w, --warning Show warning on substitution operation resulting in no content change on every file. The default is to show a warning on substitution operations resulted in no content change on all files. -q, --quiet Suppress warning on substitution operation resulting in no content change. -s, --stealth Stealth operation. Preserve timestamp on file. -i, --interactive Enter interactive mode where the user has to approve each operation. -b, --backup ext Preserve backup of original file using file name extension ext. Default is to overwrite the original file. -e, --exec cmd Specify sed(1) command directly. -f, --file cmd-file Read sed(1) command from file. EXAMPLE
# shell script shtool subst -i -e 's;(c) ([0-9]*)-2000;(c) 1-2001;' *.[ch] # RPM spec-file %install shtool subst -v -n -e 's;^(prefix=).*;1 $RPM_BUILD_ROOT%{_prefix};g' -e 's;^(sysconfdir=).*;1 $RPM_BUILD_ROOT%{_prefix}/etc;g' `find . -name Makefile -print` make install HISTORY
The GNU shtool subst command was originally written by Ralf S. Engelschall <rse@engelschall.com> in 2001 for GNU shtool. It was prompted by the need to have a uniform and convenient patching frontend to sed(1) operations in the OpenPKG package specifications. SEE ALSO
shtool(1), sed(1). 18-Jul-2008 shtool 2.0.8 SHTOOL-SUBST.TMP(1)
All times are GMT -4. The time now is 11:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy