05-03-2019
To add: in regular expressions, a . (dot) has a special meaning as it stands for "any character" . In order to change the meaning to a literal dot, it can be escaped with a \ character (backslash) preceding the dot. The %-sign is not a special character here and therefore does not need to be escaped.
Last edited by Scrutinizer; 05-03-2019 at 01:27 AM..
This User Gave Thanks to Scrutinizer For This Post:
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
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
Hi,
For the following complex code ,
<!-- ... (2 Replies)
Discussion started by: fed.linuxgossip
2 Replies
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
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
5. Shell Programming and Scripting
Hello experts
I am trying to write a shell script which will add ' ' to a unix variable and then pass it to oracle for inserting to a table.
I am running the script as root and I have to do a su -c .
The problem is the character ' is not recognised inside sed even after adding escape... (1 Reply)
Discussion started by: pvedaa
1 Replies
6. Shell Programming and Scripting
Hello Everyone,
I need to read an encrypted password from the user and update that value in an xml file. I am trying to use "sed" for searching the appropriate tag and replacing this new value that get from the user. Since the encrypted password can contain special characters(like /,\,&,etc),... (4 Replies)
Discussion started by: majose
4 Replies
7. Shell Programming and Scripting
Need help in escaping special characters in sed command.
Here is the the string which i am trying to find a replace with
From :- REQUEST_TYPE=PIXEL&MSG_ID={//MESSAGE_ID}
To :- REQUEST_TYPE=PIXEL&MSG_ID= X_EDELIVERY_MESSAGE_ID & BATCH_ID= X_EDELIVERY_BATCH_ID
Here is the sed command i am... (2 Replies)
Discussion started by: aakishore
2 Replies
8. Shell Programming and Scripting
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
9. Shell Programming and Scripting
Friends,
In the file i am having more then 100 lines like,
File1 had the values like this:
#Example East.server_01=EAST.SERVER_01
East.server_01=EAST.SERVER_01
West.server_01=WEST.SERVER_01
File2 had the values like this:
#Example EAST.SERVER_01=http://yahoo.com... (3 Replies)
Discussion started by: jothi basu
3 Replies
10. Shell Programming and Scripting
Greetings!
I've run into this before; and am having a spot of trouble trying to figure out the way that Perl would prefer the following example syntax to be formed:#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
`sed -i 's/Hi Mom!\|Hi Dad!/Bye Everyone!/I' ./test.txt`;Perl... (5 Replies)
Discussion started by: LinQ
5 Replies
LEARN ABOUT ULTRIX
basename
basename(1) General Commands Manual basename(1)
Name
basename - strip directory names from pathname
Syntax
basename string [ suffix ]
Description
The command deletes from string any prefix up to and including the last slash (/) and the suffix (if specified), and prints the result on
the standard output. The command handles limited regular expressions in the same manner as metacharacters must be escaped if they are
intended to be interpreted literally. For example:
% basename /vmunix .x
vmun
% basename /vmunix '.x'
vmunix
In the first example, returns because it interprets the as a regular expression consisting of any character followed by the letter In the
second example, the dot is escaped; there is no match on a dot followed by and returns
The command is often used inside substitution marks (` `) within shell procedures.
Examples
The following example shell script compiles the file and moves the output to in the current directory:
cc /usr/src/bin/cat.c
mv a.out `basename $1 .c`
The following example echoes only the base name of the file by removing the prefix and any possible sequence of characters following the
period in the file's name:
% basename /etc/syslog.conf '..*'
syslog
See Also
dirname(1), ex(1), sh(1)
basename(1)