There are many times when you have a file from which you want to extract specific strings based on a regex and using a capture group is a very efficient way to parse multiple strings from the same line.
I have found that sed is the easiest way to do so on the Linux command line.
Given the following input file:
This is a line of text with a year=2020 month=12 in it
This line of text does not have a year or month in it
This year=2021 is the current year the current month=1
This is the year=2021 the month=2
Let’s say that you want to extract the year and the month digits from each line and generate a line of output for each line if input that looks like:
my year: <year>, my month: <month>
You would run the following command defining two capture groups:
sed -rn 's/.*year=([0-9]+).*month=([0-9]+).*/my year: \1, my month: \2/p' input.txt
Which will output:
my year: 2020, my month: 12
my year: 2021, my month: 1
my year: 2021, my month: 2
The -rn flag tells sed to use extended regular expressions in the script and to suppress printing unless explicitly directed after we make a match.
The s command tells sed that we are going to execute a substitution and that we will define a regex, a replacement string, and optional flags.
.*year=([0-9]+).*month=([0-9]+).*
Defines two capture groups. One to look for any number of contiguous digits after year= and another for any number of contiguous digits after month=. The .* explicitly tells sed that we want to ignore any number of any type of characters between the defined groups.
my year: \1, my month: \2/p
Tells sed how to format the output to include each capture group, \1 for capture group 1 and \2 for capture group 2.
In general, I have moved to writing all of my applications to write their log output to STDOUT. This makes running them on the command line, in an IDE, on a bare metal box, VM, or in a container completely decoupled from how you store and view the logs. No more having multiple logging configs for each flavor of deployment.
In this particular case, I am running an application in a container (but it isn’t necessary that it is in a container) controlled by systemd and using rsyslog to forward all of the log messages to a specific output file. A requirement of writing log files to a local disk is that you must be able to rotate and truncate them by size so that you don’t fill up your disk; in either normal operation or some error condition that ends up inadvertently generating a large amount of log messages in a short period of time.
For the following example, we will us the service identifier my_program_identifier. You will update this to define something relevant to your deployment.
To configure your service in this manner you first need to add the appropriate options to the [Service] section of your unit file.
Then you define an rsyslog.d config file as follows for my_program.conf
$outchannel my_program_log_rotation,/var/log/my_program/my_program.log, 1073741824, /etc/my_program/log-rotate.sh
if $programname == "my_program_identifier" then :omfile:$my_program_log_rotation
& stop
In the rsyslog conf file we define an Output Channel. The TLDR; is that an output channel enables you to define the file name to which you want to write, the max size (in bytes) and a command (or path to a script or program) to run when the file reaches the limit.
In the previous example, we declare an output channel with the $outchannel directive. We then give it the identifier my_program_log_rotation. Then define the path of the log file, the max size, and a shell script that will run to rotate the file for us.
The next line defines how to act upon each of the log messages with the "my_program_identifier" that we defined in the unit file.
Following is a working sample of the log-rotate.sh script.
#!/bin/bash
LOG_DIR=/var/log/my_program
FILE_NAME=my_program.log
MAX_NUM_FILES=10
for i in `ls -1 $LOG_DIR/${FILE_NAME}.* | sort --field-separator=. -k3 -nr`
do
# Grab the number (last token) for all of the numbered files
log_num=$(echo "$i" | awk -F\. '{print $NF}')
# If it is equal to or greater than our max number of files
# just delete it.
if [ "$log_num" -ge $MAX_NUM_FILES ]
then
rm $i
continue
fi
target_num=$((log_num + 1))
target_file_name="$LOG_DIR/${FILE_NAME}.${target_num}"
mv -f $i $target_file_name
done
mv -f $LOG_DIR/$FILE_NAME $LOG_DIR/${FILE_NAME}.1
Deploy your updated unit file, your rsyslog.d conf file, and the shell script and you should have it up and running.
If you have a stand mixer this is much easier, but if all you have is a hand mixer that will work too.
Preheat oven to 350 F
Line the sheet pan with parchment paper
Cream the butter
Mix the sugar into the creamed butter
Add the egg and vanilla and mix well
Mix the flour, cornstarch, baking soda and salt
Add the flour slowly, mixing it into the butter/sugar mix
Mix n the chocolate chips
Press the dough into the pan, but don’t pack it too tightly. Ensure that you make it an even layer.
Bake it on the center rack for about 15 minutes. Rotate it about one half way through so that it will cook evenly.
Turn on the broiler and watch it very carefully. You’ll want to take it out as soon as you start to see it browning on the surface. Leave it too long and you can easily burn it. Most likely, less than 1 minute.
If you are setting up Thunderbird to use your Gmail account you may find that when Thunderbird opens a new window to a Google web portal into which you are to provide your email address and password that it will keep asking you over and over again for your email and never enable to you to enter the password.
This occurs when Thunderbird’s privacy settings do not allow it to store cookies.
First, ensure that your gmail account has Allow insecure apps off. Unfortunately, it may take some time for this setting to propagate to your account.
Than, go to Preferences > Privacy and under Web Content check the Accept cookies from sites checkbox.
Return to your account settings when when prompted you should now be able to enter your credentials to grant Thunderbird access to your account.
Admittedly, not the most savory subject. But, for those of us with pets and/or children it is sometimes a necessity to try to find a previously ingested foreign object in feces to make sure that it does not cause medical problems in the person or animal that has accidentally eaten it.
Recently, we thought our dog had eaten a relatively small magnet and figured that we would have to be checking his feces over the next few days to ensure that he passed it. I’ve not had to do this before and off the top of my head I didn’t know the best way to go about it. Turning to the Internet, all of the searches with the exact same title as this blog article turned up other articles about how long things take to move through the digestive tract. That you should call your Dr. or Vet. But nothing that specifically said how to actually search for the object in the offending matter.
Eventually, I found a blog posting on some dog owner site with a very good suggestion and here is what I did.
Collect the feces as you normally would in a poop bag and bring it home.
Cut open the bag and dump it in a quart sized or bigger ziplock freezer bag. The bigger the bag (to a point) the better.
Shake the feces to the bottom of the bag and lay it flat on your driveway, sidewalk, or similarly hard surface outside. Doing it outside makes clean-up much easier if the bag develops a rip.
Squeeze as much air out of the bag as possible while smooshing the feces out such that it is transformed into a thin layer inside the bag.
While doing so, you will easily find all but the smallest of objects just by feeling it through the bag without getting your hands dirty.
Once you identify it, you can either retrieve it from the bag and clean it off, or just toss it knowing that your child/pet has passed the item safely.
Let’s say that you have a range of lines in a source file (lines 11 – 17) that you want to comment out with a ‘#’ and a space character before the line.
To do that, you would use sed, specifying a range of lines and then specify a replacement command with a capture group as follows:
DISCLAIMER: These are my own notes learned from my own trials and tribulations of building things with concrete. They are in no way, shape or form to be taken as an expert opinion. Follow what you read here at your own risk. This is mostly notes to myself as I work through learning how to build things out of concrete.
Big Lessons Learned
Helpers
Doing this by yourself is painful. For anything more than a small job you absolutely need help. Get as many people as you can to help you.
Make a Test Piece
Before pouring 10 bags of concrete in your project, mix a bag and make something that can use and get a feel for how to mix, pour, screed, trowel, finish and cure a piece of concrete. In general the videos online and the directions on the bag that you will buy will highly simplify this process. Moreover, the amount of water that the manufacturer suggested to mix with a bag of their concrete was not nearly enough to get it to the correct consistency.
It seems that there are a number of distinct steps when building things out of concrete. I will break them down as I see them and include information about what I have learned.
Rent or Buy a Mixer If Using More Than Three or Four Bags
Not much more else to say about this . . . unless you want to get a very good workout. On the plus side, I will say I feel like I learned what the proper consistency of the mix should be.
Tools and Equipment
Heavy duty chemical resistant gauntlet gloved
Eye protection
Good dust mask
2x4s
Darby: a 1×4 with a handle on it
Rake
Hoe
Shovel
Trowel
Float
Edger
Groover
Mixing bin and/or concrete mixer
Temperatures and Weather
50 degrees F or greater for at least a week. Below 45 degrees the hydration process stops completely. If it will go below that temperature have blankets handy to keep it warm.
No rain within the first 6 hours of pouring.
Buidling and Prepping the Forms
I built forms out of a combination of plywood, 2x4s and 2x6s. In order to prevent the concrete from bonding to the surface of the wood I coated the wood with used motor oil and gear oil. The gear oil was really old and I was going to recycle it anyway. It was much thicker than used motor oil from one my cars. When I ran out of the gear oil, I at first tried used oil from a car but instead used used Motul 300v out of my track bike. The bike oil was more lightly used as I change it often. It didn’t seem to make a difference in being able to remove it from the formed concrete.
I affixed the forms to the ground with a combination of 2x4s with sharpened ends that I pounded into the ground and cutting slots in the clay soil that the plywood fit into.
If I were building a very large slab I’d have to revisit the construction of the part of the forms that affixed them to the ground.
For the box that I build, the inside walls of the form were about 8 inches taller than the top of the concrete box. This worked out really well because it made it much easier for me to just dump the concrete into the form. Had the interior wall been flush with the top of where I wanted the wall to be I would have had to put it into the form a shovel at a time.
Mixing the Concrete
This seems to be probably the most difficult part of the job to get correct. My first real project was a 45″x35″x16″ outer measurement drainage catch basin with 6″+ inch steel reinforced walls.
I should have either rented or purchased a concrete mixer, however it was a good lesson in actually lerning how to mix it correctly.
Because the structure that I was making was a concrete box with a pipe cast into it I ended up making in it two pours. The first, the bottom of the box, and the second the walls of the box with the pip cast into it.
I found a really good tutorial on how to actually mix the concrete with a rake that worked out well. Towards the end of the process I used a hoe, however I believe that I ended up mixing it too dry. The idea is to put all of the dry mix on one side of the mixing bin, then pour the water onto the other side. Then a bit at a time, drag some of the dry concrete mix into the water and completely mix it before going back to the dry pile at the other end of the bin. Continue until the whole bag is evenly mixed.
Based on my experience I would suggest using the directions on the bag as a starting point. In my case, it was just plain wrong and not enough water.
To get the amount of water consistent, create a measuring bucket and measuring out the recommended amount of water into and mark a line on it. Then, dump that water into another bucket and then fill up measuring bucket again to the line that you just marked.
Then, when mixing your first couple use the following procedure to keep track of the total amount of water your need.
Mix the initial amount of water into your mix from the second bucket
If you need more water, measure it out before adding it to your mix and add the same amount of water to your mix AND the first measuring bucket.
Keep doing this until you reach the right consistency and then RE-MARK your line on your first measuring bucket
Now you will have the correct amount of water that you can add to each batch that you mix. This is much easier than spraying a bit at a time into your mix to get it correct and makes the entire pour more consistent.
This is a very good picture that illustrates what the mix should look like. Instead of just linking the the page, I am including it here in case that site goes away.
“The mix is just right when the sides of the trough stand and the ingredients are thoroughly wetted. A hoe patted against the concrete will leave a slightly shiny surface.”
In my case, I made a big mistake and got freaked out about what I read about putting too much water in the concrete and focused too closely on the amount of water that the manufacturer suggested. Which, by the way, was not nearly enough.
Between batches, have your helper rinse off your tools so that they don’t get caked with concrete.
Pouring the Concrete
Depending on the shape of your form, you can either dump the entire wheelbarrow or mixing basin into your form or shovel it into place.
After I did a layer of concrete around the whole of the box, I poked at the concrete with a thin stake (should have used a piece of rebar) to get it to settle and consolidate and then pounded on all sides of the form with a rubber mallet.
Unfortunately, I didn’t do this for all of the layers because I got freaked out that I was pouring it to wet as I saw water percolating to the top of the layer. In retrospect, this is exactly what I should have been seeing.
I had a lip, under which I wanted to create a concrete ledge on the inside of the box. Had my concrete been wetter and of a better consistency I could have worked it under the lip by simply jiggling the surface with my (gloved) hand or the face of the hoe. Next time.
Screeding
Once the form is filled to the top, push or pull the appropriately sized 2×4 using a sawing motion as you move accross the surface using your form as a guide.
In this case, I wanted the bottom of the box to be at a slope but could not have forms in the bottom of the box. I tied string to the vertical rebar to use as a guide and simply screeded the concrete uphill to make the slope that I wanted.
Darby or Bull Float
Immediately thereafter, sweep the darby across the concrete to help smooth the surface. Do this in overlapping arcs with the leading edge of the 1×4 slightly raised. Do two passes.
The screed and darby’s purpose is to help to force the aggregate down into the piece and leave the slurry of sand and cement to fill the surface and eventually provide a smooth, solid finish.
Do not over-work the concrete at this stage or it may pull too much sand and concrete to the surface and ultimately making the surface weaker than it should be.
Waiting for Bleed Water to Evaporate
At this point water will appear on the surface of the concrete. It was during this phase when I did the first pour, the bottom of the box, that I got freaked out that I made the concrete mix too wet. When, in reality, it was probably just right. Water will come to the surface and actually sit on top of the concrete.
You will need to simply wait until it evaporates. You will know when enough of it has evaporated when the sheen is gone from the surface, and the concrete starts to harden.
At this point you can move onto the finishing stage.
Finishing
Edging
Edging will remove sharp edged from where the concrete meets the form making it less likely for the edges to break off.
Grooving
Grooving helps guide where cracks may occur.
You can use a board layed across the form to guide straight lines.
Float
Trowling
Brooming
Pulling the Forms
The concrete that I used indicated about 24 hours before pulling the forms.
When I did, I realized that I had mixed my concrete a bit too dry.
More on how I attempted to address that later.
Curing
Based on my reading curing is both an art an a science and not at all simple. It seems the most common method of curing concrete is “Wet Curing”; essentially hosing it down with water 5 – 10 times a day for the first week. Covering it also helps keep the moisture in if you cannot be so attentive to your new concrete. In that case, hose it down once a day, then cover it for the first week.
The curing process should be started once the concrete starts to harden, should not be allowed to dry fast and maintained at least the first 24 hours.
The science of it is based in the chemistry of how concrete hardens. My basic understanding of it is that the curing (also referred to as hydration) of the concrete is the process by which the water blends with the aggregate, cement, and sand to form a crystalline lattice structure that provides the strength in the concrete.
Completely cured concrete takes up to about 30 days.
It seems that the key to curing concrete properly is controlling the moisture content of the concrete. After it is hardened enough that the surface cannot be easily damaged 2 – 6 hours or so depending on the temperature and humidity, it should be gently hosed down to keep it wet. You can also put a tarp, or plastic covering, or a layer of burlap soaked in water over it. It seems the key is to not let the surface dry out such that the concrete can cure over time.
It seems it should be kept wet for at least 7 days
Drying
Painting, Staining, and Sealing
Wait at least 30 days until it is completely cured.
Alternatively, you can also generate a key cert pair to use if you have to test importing of certs
To do so, first generate a self-signed cert and an ssl key without a passphrase for your nc “server”. Place the server.key and server.cert file in /var/tmp/server-cert
while true; do { echo -e “HTTP/1.1 200 OK\r\n$(date)\r\n\r\n<h1>hello world from $(hostname) on $(date)</h1>” | nc -vl –ssl 8080 –ssl-key /var/tmp/server-cert/server.key –ssl-cert /var/tmp/server-cert/server.cert; } done