backslash

Escaping backslash in AWK

若如初见. 提交于 2020-08-10 18:47:31
问题 I'm trying to understand why the command below doesn't work (output is empty): echo 'aaa\tbbb' | awk -F '\\t' '{print $2}' I would expect the output to be 'bbb'. Interestingly this works (output is 'bbb'): echo 'aaa\tbbb' | awk -F 't' '{print $2}' And this works as well (ouptut is 'tbbb'): echo 'aaa\tbbb' | awk -F '\\' '{print $2}' It looks as if \\\t is read as backslash followed by tab instead of escaped backslash followed by t . Is there a proper way to write this command? 回答1: You need to

Escaping backslash in AWK

醉酒当歌 提交于 2020-08-10 18:47:08
问题 I'm trying to understand why the command below doesn't work (output is empty): echo 'aaa\tbbb' | awk -F '\\t' '{print $2}' I would expect the output to be 'bbb'. Interestingly this works (output is 'bbb'): echo 'aaa\tbbb' | awk -F 't' '{print $2}' And this works as well (ouptut is 'tbbb'): echo 'aaa\tbbb' | awk -F '\\' '{print $2}' It looks as if \\\t is read as backslash followed by tab instead of escaped backslash followed by t . Is there a proper way to write this command? 回答1: You need to

Exactly how do backslashes work within backticks?

一世执手 提交于 2020-07-15 04:29:35
问题 From the Bash FAQ: Backslashes (\) inside backticks are handled in a non-obvious manner: $ echo "`echo \\a`" "$(echo \\a)" a \a $ echo "`echo \\\\a`" "$(echo \\\\a)" \a \\a But the FAQ does not break down the parsing rules that lead to this difference. The only relevant quote from man bash I found was: When the old-style backquote form of substitution is used, backslash retains its literal meaning except when followed by $, `, or . The "$(echo \\a)" and "$(echo \\\\a)" cases are easy enough:

Python Regex escape operator \ in substitutions & raw strings

倾然丶 夕夏残阳落幕 提交于 2020-04-26 05:56:09
问题 I don't understand the logic in the functioning of the scape operator \ in python regex together with r' of raw strings. Some help is appreciated. code: import re text=' esto .es 10 . er - 12 .23 with [ and.Other ] here is more ; puntuation' print('text0=',text) text1 = re.sub(r'(\s+)([;:\.\-])', r'\2', text) text2 = re.sub(r'\s+\.', '\.', text) text3 = re.sub(r'\s+\.', r'\.', text) print('text1=',text1) print('text2=',text2) print('text3=',text3) The theory says: backslash character ('\') to

Python Regex escape operator \ in substitutions & raw strings

◇◆丶佛笑我妖孽 提交于 2020-04-26 05:51:07
问题 I don't understand the logic in the functioning of the scape operator \ in python regex together with r' of raw strings. Some help is appreciated. code: import re text=' esto .es 10 . er - 12 .23 with [ and.Other ] here is more ; puntuation' print('text0=',text) text1 = re.sub(r'(\s+)([;:\.\-])', r'\2', text) text2 = re.sub(r'\s+\.', '\.', text) text3 = re.sub(r'\s+\.', r'\.', text) print('text1=',text1) print('text2=',text2) print('text3=',text3) The theory says: backslash character ('\') to

How can I insert a variable containing a backslash in sed?

不打扰是莪最后的温柔 提交于 2020-03-16 08:01:50
问题 Please see these simple commands: $ echo $tmp UY\U[_ $ echo "a" | sed "s|a|${tmp}|g" UY[_ The \U is eaten. Other backslashes won't survive either. How can I make the above command work as expected? 回答1: If it's only backslash that is "eaten" by sed and escaping just that is enough, then try: echo "a" | sed "s|a|${tmp//\\/\\\\}|g" Confusing enough for you? \\ represents a single \ since it needs to be escaped in the shell too. The inital // is similar to the g modifier in s/foo/bar/g , if you

How can I insert a variable containing a backslash in sed?

血红的双手。 提交于 2020-03-16 08:01:10
问题 Please see these simple commands: $ echo $tmp UY\U[_ $ echo "a" | sed "s|a|${tmp}|g" UY[_ The \U is eaten. Other backslashes won't survive either. How can I make the above command work as expected? 回答1: If it's only backslash that is "eaten" by sed and escaping just that is enough, then try: echo "a" | sed "s|a|${tmp//\\/\\\\}|g" Confusing enough for you? \\ represents a single \ since it needs to be escaped in the shell too. The inital // is similar to the g modifier in s/foo/bar/g , if you

How to type Backslash in VScode on Linux

偶尔善良 提交于 2020-03-05 05:31:07
问题 I'm using Visual Studio Code on an Ubuntu 18.04 laptop. I'm loving the editor, but I can't seem to be able to type the backslash ( \ ). When I click the backslash I only see the status bar saying: (\) was pressed. Waiting for second key of chord... I googled the error above and found this SO thread which talks about the same error when hitting Ctrl + E .The highest upvoted answer says that I need to "remove all the shortcuts that use the Ctrl + E chord" . But I can't find any with just a

Double backslash prints the same in node

风流意气都作罢 提交于 2020-01-30 10:56:07
问题 I want to create a directory string variable which is '.\app\src\algorithms' to use it in exec function in node on Windows Platform. However, it doesn not work properly even use double backslashes in the string. Here is my try; λ node > directory = '.\app\src\algorithms'; '.appsrcalgorithms' > directory = '.\\app\\src\\algorithms'; '.\\app\\src\\algorithms' 回答1: What you have is fine. Internally it's stored as a double backlash because that's how escaping backslashes works in JS strings. The

Regex expression in C++ and double backslash

末鹿安然 提交于 2020-01-30 08:35:05
问题 I'm reading a text file in the form of People list [Jane] Female 31 ... and for each line I want to loop through and find the line that contains "[...]" For example, [Jane] I came up with the regex expression "(^[\w+]$)" which I tested that it works using regex101.com. However, when I try to use that in my code, it fails to match with anything. Here's my code: void Jane::JaneProfile() { // read each line, for each [title], add the next lines into its array std::smatch matches; for(int i = 0;