Why double "\" required?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why double "\" required?
# 1  
Old 04-09-2018
Why double "\" required?

Hi Gurus,

Below command give error if i put single "\", If I put two, it works. my understanding is: we can use "\" to escapt the special characters. why here I need to put two "\". The system I am working on is SunOS 5.10 Generic_150400-04 sun4v sparc sun4v

Code:
echo "SUCCESS(ABCD)" |nawk '{gsub("SUCCESS\\(", "")}1'
ABCD)

echo "SUCCESS(ABCD)" |nawk '{gsub("SUCCESS\(", "")}1'
nawk: illegal primary in regular expression SUCCESS( at 
 source line number 1
 context is
        {gsub("SUCCESS\(", >>>  "") <<<


Last edited by rbatte1; 04-09-2018 at 01:43 PM.. Reason: Added CODE tags
# 2  
Old 04-09-2018
It is because awk substitutes \ in strings. For example
Code:
nawk 'BEGIN {print "\a"}' </dev/null
nawk 'BEGIN {print "\b"}' </dev/null

So within " " you need \\ for a literal \
Therefore, you better have regular expressions in / /
Code:
echo "SUCCESS(ABCD)" | nawk '{gsub(/SUCCESS\(/, "")}1'

This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 04-09-2018
Hello green_k,

\\( means escape \ to remove its special meaning. If you will put ( without \ will be treated as sub's starting ( parenthesis and it will give error.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Homework & Coursework Questions

Compiler error "lvalue required as left operand of assignment"

1. After trying to compile code error is given Lvalue required as left operand of assignment. 2. Relevant commands, code, scripts, algorithms: if , else if 3. The attempts at a solution (include all code and scripts): /* File: incircles.cpp Created by: James Selhorst ... (2 Replies)
Discussion started by: c++newb
2 Replies

5. Programming

"lvalue required as left operand of assignment" error in C

Hey all. I've been working on some fun with C and decided to write a Rock Paper Scissors game. The problem is, that when I try to compile the file, it gives "lvalue required as left operand of assignment" error. The error line is here: for ((point1=0 && point2=0); ((point1=3) || (point2=3));... (4 Replies)
Discussion started by: drouzzin
4 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Solaris

sendmail "root... User address required." error

I'm running sendmail (8.13.8+Sun/8.13.8/Submit) solaris 10. When I send mail to root at the command line (whether I use a full-qualified address or just root), I get the error message root... User address required. Sending mail to root (either at the command line or in a cron job),... (10 Replies)
Discussion started by: csgonan
10 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question