[Solved] Extract variable names from file [closed]

I don’t know about sed or R, but in Python: >>> import re >>> i = “””NOTE: Variable Variable_S1 already exists on file D1.D, using Var_S8 instead. NOTE: The variable name more_than_eight_letters_m has been truncated to ratio_s. NOTE: Variable ratio_s already exists on file D1.D, using Var_S9 instead.””” >>> print(re.findall(r'(\w+_\w+)’, i)) [‘Variable_S1’, ‘Var_S8’, ‘more_than_eight_letters_m’, ‘ratio_s’, … Read more

[Solved] shell – remove numbers from a string column [closed]

You should have been more clearer when you raise the problem. Do not add test cases later You can try this, I have modified the third field to last but one. But credit to @Kaz ~> more test SER1828-ZXC-A1-10002 SER1878-IOP-B1-98989 SER1930-QWE-A2-10301 SER1930-QWE-A2-10301 SER1930-QWS_GH-A2-10301 SER1930-REM_PH-A2-10301 SER1930-REM-SEW-PH-A2-10301 SER1940-REM-SPD-PL-D3-10301 ~> awk -F- ‘BEGIN { OFS=”-” } { sub(/[0-9]/,””,$(NF-1)); … Read more

[Solved] sed, awk, perl or lex: find strings by prefix+regex, ignoring rest of input [closed]

If you won’t have more than one of the pattern on a single line, I’d probably use sed: sed -n -e ‘s%.*https://\([-.0-9A-Za-z]\{1,\}\.[A-Za-z]\{2,\}\).*%\1%p’ Given the data file: Nothing here Before https://example.com after https://example.com and after Before you get to https://www.example.com And double your https://example.com for fun and happiness https://www.example.com in triplicate https://a.bb and nothing here The … Read more

[Solved] Bash: Remove all occurring pattern except 1

With no sample input, I will just guess and maybe it will help: cat file header for file 1111 header for file 1111 2222 header for file 3333 4444 5555 awk ‘/header/&&c++>0 {next} 1’ file header for file 1111 1111 2222 3333 4444 5555 Though I am not the greatest in sed sed ‘1!{/^header/d;}’ file … Read more

[Solved] how to remove a substring of unknown length from a string – C++ [closed]

Use rfind to get the location of the last slash then substr to return the right side of the string. Since substr‘s second argument defaults to “the end of the string” you only need to provide the beginning position: #include <string> std::string GetURLFilePath(const std::string& url) { auto last_slash_location = url.rfind(“https://stackoverflow.com/”); if(last_slash_location == std::string::npos || last_slash_location … Read more