Pasting multi line text in AWS SSM connection - amazon-web-services

I have used both AWS SSM on the web UI and also installing the SSM plugin on my terminal (Using MacOS Monterrey Terminal) and on both I have the same odd behaviour when pasting multi-line text:
My source text:
"Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
Ut enim ad minim veniam"
When pasting it in a file inside my Amazon Linux 2 instance connected through SSM (both Web and CLI plugin)
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam"
I expect it to paste the source text exactly including all the line break characters, like it does when one connects using plain SSH.
It def seems to be omitting the line break characters \n or carry return character. Not sure how to proceed.

Which editor are you using? I noticed the same weird behavior with nano but fortunately, if you use vi, your formatting is respected in both the AWS SSM web UI and via the SSM plugin.

Related

Find content inside parentheses and the word that comes before it (OpenRefine)

I'm trying to extract some text from a column on a CSV file. Here is an example:
"Lorem ipsum dolor sit amet (2015), consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua (2000)."
I wanna get a new column with "amet (2015)" and "aliqua (2000)". This expression gives me the (2015) and (2000): value.find(/(.*?)/)
But how can I also get the word before the parentheses?
here is the regex your are looking for /\w* \([^\)]*\)/gm.

How to prevent pieces of colored text in the command line turning back white using std::wcout?

I recently got back into C++ and this is just beyond me. This cmd app, when compiled using the debugger in VS2022, looks perfectly as it should. However, when I run the compiled project executable, a seemingly random piece of text often changes its color to the default white.
It's obviously not noticeable when it happens with white text, but I intend to use SetConsoleTextAttribute (or any other way to print colored text) in my program, as well as Unicode support, which _getline does just fine.
It appears to be caused by wcout, as removing _setline and changing them back to the narrow type fixed the issue. However, just removing _setline doesn't do anything.
Code:
#include <iostream>
#include <fcntl.h>
#include <Windows.h>
#include <io.h>
using namespace std;
int main() {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
fflush(stdout);
(void)_setmode(_fileno(stdout), _O_U16TEXT);
SetConsoleTextAttribute(hConsole, 10);
wcout << L"Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n";
wcout << L"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n";
SetConsoleTextAttribute(hConsole, 11);
wcout << L"Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n";
wcout << L"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n";
SetConsoleTextAttribute(hConsole, 12);
wcout << L"Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n";
wcout << L"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n";
cin.get();
}
EDIT: Using wmain instead of main and calling fflush wherever it made the tiniest bit of sense didn't fix anything either. Weird.
I seem to have fixed it! Using wmain instead of _setline, setting locale to "" at the beginning and flushing stdout before main returns 0 makes the problem disappear with Unicode still being supported.
Like this:
#include <iostream>
#include <locale>
#include <Windows.h>
using namespace std;
int wmain() {
setlocale(LC_ALL, "");
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, 10);
wprintf(L"Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n");
wprintf(L"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n");
SetConsoleTextAttribute(hConsole, 11);
wprintf(L"Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n");
wprintf(L"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n");
SetConsoleTextAttribute(hConsole, 12);
wprintf(L"Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n");
wprintf(L"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n");
cin.get();
}

REGEX - Select multiple lines unless it finds the defined stop charecter

I have a String
Lorem ipsum dolor sit amet
*consectetur adipiscing elit
sed do eiusmod tempor incididunt*
ut labore et dolore magna aliqua
Ut enim ad minim veniam.
now I want to select the * content *
this [*](.*?)[*] is my current regex, but it's working with a single line
*consectetur adipiscing elit*
How do I make it multiline?
This REGEX worked for me [*]([\\s\\S]*?)[*]

Regex match multiple pattern

Below is my test string:
Object: TLE-234DSDSDS324-234SDF324ER
Page location: SDEWRSD3242SD-234/324/234 (1)
org-chart Lorem ipsum dolor consectetur adipiscing # Colorado
234DSDSDS324-32-4/2/7-page2 (2) loc log Apr 18 21:42:49 2017 1
Page information: 3.32.232.212.23, Error: fatal, Technique: color
Comments: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Validation status: Lorem ipsums dolors sits amets, consectetur adipiscing elit
Positive control-export: Validated
Page location: SDEWRSD3242SD-SDF/234/324 (5)
org-chart Lorem ipsum dolor consectetur adipiscin # Arizona
234DSDSDS324-23-11/1/0-page1 (1) loc log Apr 18 21:42:49 2017 1
Page information: 3.32.232.212.23, Error: log, Technique: color
Comments: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Validation status: Lorem ipsums dolors sits amets, consectetur adipiscing elit
Positive control-export: Validated
I need to capture strings after the "Page location: ", "Object: " and "Comments: "
For example:
Object: TLE-234DSDSDS324-234SDF324ER - Group 1
Page location: SDEWRSD3242SD-234/324/234 (1) - Group 2
Page location: SDEWRSD3242SD-SDF/234/324 (5) - Group 3
Comments: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - Group 4
Comments: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - Group 5
Here is my regex URL.
I am able to capture the strings but the regex won't capture if any one of the string is repeated.
(See comments below the question for the problem description.)
The data is in a multi-line string, with multiple sections starting with Object:. Within each there are multiple lines starting with phrases Page location: and Comments:. The rest of the line for all these need be captured, and all organized by Objects.
Instead of attempting a tortured multi-line "single" regex, break the string into lines and process section by section. This way the problem becomes a very simple one.
The results are stored in an array of hashrefs; each has for keys the shown phrases. Since they can appear more than once per section their values are arrayrefs (with what follows them on the line).
use warnings;
use strict;
use feature 'say';
my $input_string = '...';
my #lines = split /\n/, $input_string;
my $patt = qr/Object|Page location|Comments/;
my #sections;
for (#lines)
{
next if not /^\s*($patt):\s*(.*)/;
push #sections, {} if $1 eq 'Object';
push #{ $sections[-1]->{$1} }, $2;
}
foreach my $sec (#sections) {
foreach my $key (sort keys %$sec) {
say "$key:";
say "\t$_" for #{$sec->{$key}};
}
}
With the input string copied (suppressed above for brevity), the output is
Comments:
Lorem ipsum dolor sit amet, [...]
Lorem ipsum dolor sit amet, [...]
Page location:
SDEWRSD3242SD-234/324/234 (1)
SDEWRSD3242SD-SDF/234/324 (5)
Object:
TLE-234DSDSDS324-234SDF324ER
A few comments.
Once the Object line is found we add a new hashref to #sections. Then the match for a pattern is set as a key and the rest of its line added to its arrayref value. This is done for the current (so last) element of #sections.
This adds an empty string if a pattern had nothing following. To disallow add next if not $2;
Note. An easy and common way to print complex data structures is via the core module Data::Dumper. But also see Data::Dump for a much more compact printout.

How to select multiple lines using regex?

I have to format 50k lines of chat logs.
The source file is pure text and looks something like this:
13. Mär. 01:32 - Walter:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
13. Mär. 06:15 - Horst:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua.
magna aliquyam erat, sed diam voluptua.
There are only two persons in the whole chat - Walter and Horst.
I need two regular expressions, one that selects all chat text from Walter and one that selects all chat text from Horst.
The regular expression for Walter should select this text from the example:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
The regular expression for Horst should select this text from the example:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua.
magna aliquyam erat, sed diam voluptua.
It's important to me to only select the text lines and not the date / time / person line.
UPDATE
First off, thanks for the fast reply. Unfortunately this doesn't solve my problem.
Chat texts have a varying line of numbers.
And somehow I cannot get a selection with your example.
I tried it here:
http://regexr.com/39m2a
I tried this instead:
Walter:.\n(.)
This selects Walter: and the first line. Is there away NOT to select Walter: ?
(I need this to format an Indesign Document using text formats)
These are actualy 2 questions
How to do a match across newlines (asked in the question title)
How to do a match that discards the date/time/person (asked in
the question body)
I'll answer question 1:
Before doing the match you want to change the line separator/record separator.
This separator is tool dependent (it is not part of the regex language itself). E.g. for awk you can change the RS variable (you can set it to multiple characters, e.g., colon+newline). For GNU grep you can use -z. See longer discussion at
How to find patterns across multiple lines using grep?
Here's my solution:
awk '$5~/Walter:$/{p=1} $5!~/Walter:$/&&$5~/:$/{p=0} p'
or
awk -vname=Walter 'match($5,name":$"){p=1} !match($5,name":$")&&$5~/:$/{p=0} p'
To filter out empty and date lines, pipe through
awk '$5!~":$"&&NF>0'
try it here: http://refiddle.com/1iws
I have modified the regex so could work on you data, but once again your data isn't well structured though it's not possible to write a single regex that would match it correctly