sed

What does \0 mean in sed?

南笙酒味 提交于 2020-07-08 20:45:08
问题 I have the following code: echo "12. Chapter Name" | sed -n -E "s/([0-9]{2})\.[[:space:]].*/\1/p" It prints 12 as expected, since \1 refers to the first capturing group. However, if \0 is used instead of \1 , the output is 12. Chapter Name , the entire input string is printed. It seems that as long as the regex found a match, \0 prints the entire input string. Is this correct? I'm running Debian 10.2. 回答1: The \0 is a placeholder for the whole match value. Note that capturing group indices

What does \0 mean in sed?

倾然丶 夕夏残阳落幕 提交于 2020-07-08 20:44:29
问题 I have the following code: echo "12. Chapter Name" | sed -n -E "s/([0-9]{2})\.[[:space:]].*/\1/p" It prints 12 as expected, since \1 refers to the first capturing group. However, if \0 is used instead of \1 , the output is 12. Chapter Name , the entire input string is printed. It seems that as long as the regex found a match, \0 prints the entire input string. Is this correct? I'm running Debian 10.2. 回答1: The \0 is a placeholder for the whole match value. Note that capturing group indices

How to remove words of a line upto specific character pattern…Regex

拟墨画扇 提交于 2020-07-07 06:44:04
问题 I want the words after "test" word from a line in a file. means in actuaaly, i dont want the words coming before "test" word. thats the pattern... e.g: Input: ***This is a*** test page. ***My*** test work of test is complete. Output: test page. work of test is complete. 回答1: Using sed: sed -n 's/^.*test/test/p' input If you want to print non-matching lines, untouched: sed 's/^.*test/test/' input The one above will remove (greedily) all text until the last test on a line. If you want to delete

sed regex to non-greedy replace?

白昼怎懂夜的黑 提交于 2020-07-06 17:39:59
问题 I am aware of another question that is quite similar, but for some reason I'm still having problems. I have a GC log that I'm trying to trim out the Tenured section enclosed in [] . 63.544: [GC 63.544: [DefNew: 575K->63K(576K), 0.0017902 secs]63.546: [Tenured: 1416K->1065K(1536K), 0.0492621 secs] 1922K->1065K(2112K), 0.0513331 secs] I apply s/\[Tenured:.*\]// And quite expectantly, the result is trimmed greedily through the remainder of the line: 63.544: [GC 63.544: [DefNew: 575K->63K(576K),

sed regex to non-greedy replace?

╄→гoц情女王★ 提交于 2020-07-06 17:37:45
问题 I am aware of another question that is quite similar, but for some reason I'm still having problems. I have a GC log that I'm trying to trim out the Tenured section enclosed in [] . 63.544: [GC 63.544: [DefNew: 575K->63K(576K), 0.0017902 secs]63.546: [Tenured: 1416K->1065K(1536K), 0.0492621 secs] 1922K->1065K(2112K), 0.0513331 secs] I apply s/\[Tenured:.*\]// And quite expectantly, the result is trimmed greedily through the remainder of the line: 63.544: [GC 63.544: [DefNew: 575K->63K(576K),

Finding and replacing lines that begin with a pattern

只谈情不闲聊 提交于 2020-07-06 11:28:05
问题 I have a text in a file file.txt like this xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx a b c // delimited by tab xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx I know using sed I can find and replace text in a file. If a line starts with a b(seperated by a tab) I need to replace it with d e f. So the above file will be xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx d e f // delimited by tab xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx I can do this to find and replace, I want only those instances where the line starts with a b and replace the

Bash Separate values with commas then surround them with quotes in variable

a 夏天 提交于 2020-07-03 13:32:09
问题 I have the below bash script: STR1="US-1234 US-7685 TKT-008953" #STR2= "${STR1// /,}" STR2=`echo $STR1 | sed 's/ /,/g'` echo $STR2 Current output: US-1234,US-7685,TKT-008953 Expected output: 'US-1234','US-9754','TKT-007643' 回答1: With bash and its parameter expansion: STR1="US-1234 US-7685 TKT-008953" STR1="${STR1// /\',\'}" STR1="${STR1/#/\'}" echo "${STR1/%/\'}" Output: 'US-1234','US-7685','TKT-008953' 回答2: You may use STR2="'$(echo "$STR1" | sed "s/ /','/g")'" See online demo All spaces are

How can I replace 'bc' tool in my bash script?

一曲冷凌霜 提交于 2020-06-29 13:49:09
问题 I have the following command in my bash script: printf '\n"runtime": %s' "$(bc -l <<<"($a - $b)")" I need to run this script on around 100 servers and I have found that on few of them bc is not installed. I am not admin and cannot install bc on missing servers. In that case, what alternative can i use to perform the same calculation? Please let me know how the new command should look like 回答1: In case you need a solution which works for floating-point arithmetic you can always fall back to

AWK inside a loop for making multiple files form single files

这一生的挚爱 提交于 2020-06-29 03:58:47
问题 I have the below file named ABCD.vasp : # A B C D 1.000000 13.85640621 0.00000000 0.00000000 4.61880236 13.06394496 0.00000000 0.00000000 0.00000000 45.25483322 A B C D 32 32 32 32 Selective dynamics Direct 0.00000000 0.00000000 0.00000000 F F F 0.00000000 0.00000000 0.12500000 F F T 0.00000000 0.00000000 0.25000000 F F T 0.00000000 0.00000000 0.37500000 F F T 0.50000000 0.00000000 0.00000000 F F F 0.50000000 0.00000000 0.12500000 F F T 0.50000000 0.00000000 0.25000000 F F T 0.50000000 0

sed command to replace dots

耗尽温柔 提交于 2020-06-27 18:36:12
问题 I have a number of scripts, in which i want to scan a particular type of string, and replace dots in those strings alone. We are replacing our locator strategy from map to something else, so the variables have to be changed from having dots to having underscore In the below, I want to change driver.click(objectMap.getIdentifier(new.dropdown), "DropDown clicking"); TO driver.click(new_dropdown, "DropDown clicking"); So 2 things : remove the text objectMap.getIdentifier Replace the enclosed