Replace file content starts with number) and preserving rest of line content - sed

I would like to replace file contains special pattern with sed or similar solutions. I can replace file with individual sed but number can be anything and need to preserve prefix as it is.
Actual file:
1) L0 | Delete multiple contacts | C543072
2) L1 | Move Multiple Messages via Header toolbar Move button | C1832588
3) L1 | Move Multiple Messages contains file attachment | C2058412
- L1 | Forward message containing attachment | C1976614
- L0 | Normal message contains file attachment | PREAPPS-1488
- L3 | Forward as signed in message view | C1990347
Expected file:
FAILED - L0 | Delete multiple contacts | C543072
FAILED - L1 | Move Multiple Messages via Header toolbar Move button | C1832588
FAILED - L1 | Move Multiple Messages contains file attachment | C2058412
SKIPPED - L1 | Forward message containing attachment | C1976614
SKIPPED - L0 | Normal message contains file attachment | PREAPPS-1488
SKIPPED - L3 | Forward as signed in message view | C1990347
Tried code:
sed -i 's/- L/SKIPPED - L/' /report.txt
sed -i 's/1) L0/FAILED - L0/' /report.txt
sed -i 's/[0-9]) L/FAILED - L[0-9]/' /report.txt (doesn't preserve LX)
Is there any single command using regex to replace content along with preserving LX where string starts with number) L[number]?

Multiple commands in a sed script can be separated by semicolons (;).
$ sed 's/^[0-9]\+)/FAILED -/; s/^-/SKIPPED -/' file
FAILED - L0 | Delete multiple contacts | C543072
FAILED - L1 | Move Multiple Messages via Header toolbar Move button | C1832588
FAILED - L1 | Move Multiple Messages contains file attachment | C2058412
SKIPPED - L1 | Forward message containing attachment | C1976614
SKIPPED - L0 | Normal message contains file attachment | PREAPPS-1488
SKIPPED - L3 | Forward as signed in message view | C1990347
^ matches beginning of the input line,
[0-9]\+ matches one or more digits.

Related

unable to Write json to Pubsub topic using apache beam python

I am trying to read a topic from pubsub and do some cleanup/transfermation and write the final result to another pubsub topic. however i am ending up with the following error. pls guide me.
code:
Ingest = ( p
| 'Read from Topic' >> beam.io.ReadFromPubSub(topic=known_args.topic).with_output_types(bytes)
| 'Parse' >> beam.Map(parse_json)
| 'Cleanup' >> beam.Map(cleanup)
| 'write to pubsub' | beam.io.WriteToPubSub("projects/test/topics/cdp_aa_food" , with_attributes=False)
)
the error which i am getting is below:
raise TypeError("Expected a PTransform object, got %s" % transform)
TypeError: Expected a PTransform object, got write to pubsub
not sure what i am doing wrong..
Ingest = ( p
| 'Read from Topic' >> beam.io.ReadFromPubSub(topic=known_args.topic).with_output_types(bytes)
| 'Parse' >> beam.Map(parse_json)
| 'Cleanup' >> beam.Map(cleanup)
| 'write to pubsub' >> beam.io.WriteToPubSub("projects/test/topics/cdp_aa_food" , with_attributes=False)
)
There is a typo in your pipeline, you need >> instead of | for the write to pubsub step.

How to split a stream to multiple streams based on some ID then debounce them?

I have a publisher that emits an object which contains a few params. In the object, one of the params (called optionId) distinctly identifies an option. I'd like to debounce instances of that emission. However, if a new optionId shows up, I'd like to start a new clock, and start a new debounce.
Consider a stream like this:
Time in seconds: optionID emitted at source | what debounce(3 seconds) gets me | what I need //- means no event emitted.
00: 1 | - | -
01: 1 | - | -
02: - | - | -
03: - | - | -
04: - | 1 | 1
05: - | - | -
06: 3 | - | -
07: 1 | - | -
08: 3 | - | -
09: 1 | - | -
10: - | - | -
11: - | - | 3
12: - | 1 | 1
13: - | - | -
Your drawing has nothing whatever in common with what the Rx groupBy does. Thus your title is misleading.
Perhaps you are also misusing the word "debounce"? Debouncing has to do with timing, and nothing in your diagram shows anything about that either. Debouncing has nothing to do with what values arrive; it simply insists upon a big gap of empty time before it will pass any value downstream at all (namely the most recent value).
It seems to me more likely that you simply want the removeDuplicates() operator. That would result in 1,3,1,3,1,3,1 which is exactly the output you give.
Okay, now that you've reworded the question, it occurs to me that you might be looking for something like this (this is just a demo, but it will give you the idea):
let pub = [1,1,1,3,3,3,1,3,1,3,1].publisher
.flatMap(maxPublishers:.max(1)) { num in
Just(num).delay(for:.seconds(1), scheduler: DispatchQueue.main)
}
.share()
let p1 = pub
.filter { $0 == 1 }
.debounce(for: .seconds(1.5), scheduler: DispatchQueue.main)
let p2 = pub
.filter { $0 == 3 }
.debounce(for: .seconds(1.5), scheduler: DispatchQueue.main)
p1.merge(with: p2)
.sink { print($0, Date().timeIntervalSince1970) }
.store (in: &storage)
What I'm doing here is exactly what you said: I'm splitting the stream into two streams, based on whether this is a 1 or a 3, and I'm debouncing each of those streams before joining them back together.
The result is:
1 1614228919.57355
3 1614228922.823595
1 1614228923.923283
3 1614228925.0221992
1 1614228926.12345
If you think about those numbers, you'll see that we are indeed debouncing each value (1 or 3) separately.

getting wget error while trying to upgrade openwrt kernel

BusyBox v1.22.1 (2014-11-14 10:11:32 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -| || | | || _|| _|
|_______|| __|_____||||________||| |____|
|__| W I R E L E S S F R E E D O M
CHAOS CALMER (Bleeding Edge, unknown)
1 1/2 oz Gin Shake with a glassful
1/4 oz Triple Sec of broken ice and pour
3/4 oz Lime Juice unstrained into a goblet.
1 1/2 oz Orange Juice
1 tsp. Grenadine Syrup
root#OpenWrt:~# wget https://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/m
t7620/openwrt-15.05.1-ramips-mt7620-ArcherC20i-squashfs-sysupgrade.bin
wget: not an http or ftp url: https://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7620/openwrt-15.05.1-ramips-mt7620-ArcherC20i-squashfs-sysupgrade.bin
root#OpenWrt:~#
Replace https in your link with http:
wget http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7620/openwrt-15.05.1-ramips-mt7620-ArcherC20i-squashfs-sysupgrade.bin
Your installed version of wget doesn't support TLS (libopenssl is not installed).
Also, I would change to /tmp dir first, so that downloaded image is stored in RAM (you probably don't have enough space in flash):
cd /tmp
wget http://...

Better method to append to output crontabs

So i have simple shell commands to ping websites to retrieve data about said websites.
For example one of my pinging.sh looks like this:
ping -R -c 120 blar.org.cn >> pingdata.txt
ping -R -c 120 another.net >> pingdata.txt
But then my crontabs look like this:
7 * * * ./pinging.sh >> pingdata.log
The pingdata.log doesn't output. Is it best to do it through the crontab or through the script? I assumed the crontab would be better because it would cover the entire script rather than having to write it out multiple times.
You need to indicate the full path of your script in the cronjob, together with the binary running it.
For example:
7 * * * * /bin/sh /home/you/pinging.sh >> /home/you/pingdata.log
Note also you are just adding 4 parameters to the cronjob, whereas you need at least 5:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
You can test your cron syntax with Crontab guru (---> http://crontab.guru/).
First, the executable must be provided as full path in cron.
Example:
7 * * * * /bin/bash /path/to/pinging.sh
Second, create a wrapper script for pinging.sh >> pingdata.log and add that to crontab.
Third, your crontab entry is wrong. There must be 5 fields whereas your's have 4 (maybe that's a typo ?)

What does the line ## -9,9 +9,10 ## mean in a diff file?

Can someone please explain the third line in the sample diff output below (i.e., the one that starts with ##)? I understand the changes represented by the remaining lines but am having trouble making sense of that third line...
--- a/code/c-skeleton/Makefile
+++ b/code/c-skeleton/Makefile
## -9,9 +9,10 ##
TEST_SRC=$(wildcard tests/*_tests.c)
TESTS=$(patsubst %.c,%,$(TEST_SRC))
## -9,9 +9,10 ##
...specifies where in the source and destination files changes take place, by line number and size of the chunk being edited, both before and after the changes.
Specifically:
## -9,9 +9,10 ##
^ ^^ ^ ^^ ^
| || | || \----- The "10" is the number of lines in the hunk after being
| || | || modified; this patch, then, must add a line, since the
| || | || new count (of 10) is longer than the old count (of 9).
| || | |\------- This "9" is the line number in the new file where the
| || | | modified hunk is placed.
| || | \-------- This "+" is a hint that the following numbers refer to
| || | the new file, after modification.
| || \---------- This "9" is the number of lines in the hunk before being
| || modified.
| |\------------ This "9" is the line number in the original file.
| \------------- This "-" is a hint that the following numbers refer to the
| original file.
\---------------- This "##" is a marker indicating that this is the start of a
new hunk.
That is to say: in the original file, the hunk being modified consists of 9 lines starting at line 9; in the destination file, it's 10 lines starting at line 9.
See the detailed description of unified diff format in the GNU diffutils documentation.