avatarTeri Radichel

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2627

Abstract

C++ backend and parallelized operations.</p><div id="6c6a"><pre>mamba <span class="hljs-built_in">env</span> create -f environment.yml</pre></div><h1 id="f6a2">Poetry</h1><p id="503c">Poetry is a Python dependency management tool that’s great for packaging and dependency resolution, often used in production setups for microservices.</p><div id="d658"><pre><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># Navigate to your git repository</span> <span class="hljs-built_in">cd</span> /path/to/your/git/repository <span class="hljs-comment"># Replace with the path to your git repository</span>

<span class="hljs-comment"># 1. Install Poetry globally (you can also install it locally per-project if preferred)</span> curl -sSL https://install.python-poetry.org | bash

<span class="hljs-comment"># 2. Initialize poetry for your project (this will create a pyproject.toml and optionally a poetry.lock file)</span> poetry init

<span class="hljs-comment"># The above command will guide you through creating your pyproject.toml.</span> <span class="hljs-comment"># If you want it to interactively discover and add your dependencies, make sure you've a virtual environment activated or it will consider globally installed packages.</span> <span class="hljs-comment"># Alternatively, you can manually add dependencies later by editing the pyproject.toml file.</span>

<span class="hljs-comment"># 3. If you already know some dependencies you want to add, you can do so with:</span> <span class="hljs-comment"># poetry add <package_name></span>

<span class="hljs-comment"># For example:</span> <span class="hljs-comment"># poetry add requests</span>

<span class="hljs-comment"># 4. Commit the new/changed files to your git repository</span> git add pyproject.toml git commit -m <span class="hljs-string">"Initialize Poetry for dependency management."</span>

<span class="hljs-comment"># Optionally, if a poetry.lock is created (which it will after you add some dependencies):</span> git add poetry.lock git commit -m <span class="hljs-string">"Add Poetry lock file."</span>

<span class="hljs-comment"># 5. Whenever you want to install the project dependencies, use:</span> <span class="hljs-comment"># poetry install</span>

<span class="hljs-comment"># And that's it! You can now use Poetry for dependency management in your git repository.</span></pre></div><figure id="2588"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*paBq6pDxV-TqXtOTRAMJJw.png"><figcaption>Poetry</figcaption></figure><p id="567a">Choosing a package and environment manager for Python projects depends on

Options

various factors like the project’s requirements, your familiarity with the tool, and the specific use cases you’re targeting. Here’s a brief comparison of <code>conda</code>, <code>poetry</code>, and other common tools like <code>pipenv</code> to help guide your decision:</p><h2 id="640f">Conda</h2><p id="6292">Conda is a powerful package manager especially useful for projects that involve scientific computing and data science tools. One of its primary advantages is managing non-Python libraries with Python interfaces or dependencies, such as TensorFlow which might have specific non-Python requirements. Conda supports creating isolated environments, operates cross-platform, and can handle complex dependencies. However, it can be bulkier and slower than some other tools, and it operates in a separate ecosystem from standard Python (PyPI), which sometimes results in waiting periods for package updates. It’s ideal for projects that require non-Python dependencies or for ensuring cross-platform consistency.</p><h2 id="6633">Poetry</h2><p id="02f2">Poetry is a modern tool that simplifies both dependency management and packaging for Python projects. It offers robust dependency resolution and utilizes <code>pyproject.toml</code>, streamlining configuration. Every project gets its virtual environment, ensuring isolated dependencies. Being a newer tool, it might not be as familiar to some teams, and it's limited to managing only Python dependencies. Poetry is excellent for Python projects that require both dependency management and packaging.</p><h2 id="ed35">Pipenv</h2><p id="ffc1">Pipenv combines the best of <code>pip</code> and <code>virtualenv</code>. It provides both package and environment management in one tool. It uses <code>Pipfile</code> and <code>Pipfile.lock</code> to pin dependencies, ensuring consistent builds. While it brings together the advantages of pip and virtualenv, it can be slower in resolving dependencies than, say, poetry. Some users also find it less reliable in certain scenarios compared to conda or poetry. Pipenv is suitable for general Python application development where you want package and environment management in one place.</p><p id="11e8">The choice between these tools largely depends on the project’s requirements. Projects with non-Python dependencies or a focus on data science might lean towards conda. In contrast, pure Python projects looking for modern dependency management might prefer poetry. For more straightforward applications, pip or pipenv can suffice. The key is consistency and familiarity within your team or organization.</p></article></body>

Useful sed commands

Because I always for get these things and get error messages

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

⚙️ Check out my series on Automating Cybersecurity Metrics | Code.

🔒 Related Stories: Bugs | AWS Security | Secure Code

💻 Free Content on Jobs in Cybersecurity | ✉️ Sign up for the Email List

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note: I was using these commands on Ubuntu and find that they are not working on Amazon Linux.

Some of these may have shortcuts but I like to keep things readable (as possible with sed).

I’m using the file temp.txt below and keeping my operations separate for readability versus some tricky twisted short command. Sed is confusing enough.

I’m not a sed master but have used it successfully to manipulate output into formats I desire repeatedly. It’s a very handy tool. I’m a hacker who hasn’t memorized everything sed can do and what all the commands mean yet. I just find what works quickly as I’m usually in a hurry! So I’ll probably add commands to this over time as I use them.

I like sed better than awk. I almost never use awk — only as a last resort when I happen to stumble across an example and cannot figure out how to to it with sed — because I find it even more cumbersome than sed.

Sed is also faster than Python or just about any other option for quick text transformations.

-e

You can use -e to use multiple commands on a file or block of text.

pipe |

You can use a pipe | to run other sed commands on your initial output — so you can join different functionality together.

Replace text in output

This is the command I use most.

Replace text in some output, such as replacing a double quote with nothing to remove it.

echo '"something"'

output: 
"something"

echo '"something"' | sed 's/"//g'

output:
something

You can also use it with files with the -i switch — it will replace the characters in the content. But you’re better off testing it first and when you get the output you want, then run it on the file.

sed -i [some sed command] your-file.txt

Find and replace a value in all the files in a directory:

find . -type f -exec sed -i 's/mysecret/xxxxxxx/g' {} +

Replaces paths in a file that have a / character in them. Change the sed separator to anything else and it will work. In this case I changed the sed separator to | instead of / and then I can put the file paths in my two values to find and replace.

 find . -type f -exec sed -i 's|container/shared|job/shared|g' {} +

If you want to test first use cat to output the file, then run the command against it as shown in the next example.

Remove everything from the beginning up to a a character — an open curly brace in this example {:

sed 's/^.*{//g'

Remove everything from a character to the end — a close curly brace in this example:

sed 's/}.*$//g'

Delete all characters except alphanumeric:

sed 's|[^[:alnum:]]||g'

Delete all characters except alphanumeric and /

sed's|[^[:alnum:]/]||g'

Delete all characters except alphanumeric and / and dash -.

To treat a dash as a normal (not special) character add -r and make sure the deash is the last character in the list.

sed -r 's|[^[:alnum:]/-]||g'

Delete everything after a phrase in a file:

cat temp.txt | sed '/^###END###$/q'

or

sed -e '/^###END###$/q' temp.txt

Delete everything before a phrase in a file:

sed -e '1,/###START###/d' temp.txt

Those commands can be used to dump the results to a new file:

sed [some command and file] > some-new-file.txt

Or you can edit the file directly once you get the command working by changing -e to -i and it will update the file contents.

To remove everything up to the last occurrence of a phrase in a string

$ echo "abc123" | sed 's/^.*abc/abc/'

To remove everything up to the first occurrence of a phrase in a string:

seds/[^{{]*{{//’

To remove everything after a phrase in a string

sed 's|test.*||'

^ to insert at the beginning

sed 's/^/something/'

$ to insert something at the end

sed 's/$/something/'

Delete everything before ###START### and everything after ###END###

sed -e '/^###END###$/q' -e '1,/###START###/d' temp.txt

Delete everything before ###START### and everything after ###END### PLUS the start and end phrases

sed -e '/^###END###$/q' -e '1,/###START###/d' temp.txt | sed 's/###START###//' | sed 's/###END###//'

Replace a value in a file (use -i)

sed -i 's/somevalue/someothervalue/g' [filename]

Escape a special character like \ or ‘ with another \

sed -i 's\some\\va\'lue|someothervalue|g' [filename]

Use a different delimiter (you can use anything so in the example below I change / to | and you don’t have to escape the \.

sed -i 's|some\va\'lue|someothervalue|g' [filename]

Other resources:

You also might to check out the cut command. I often use these two commands together.

Follow for updates.

Teri Radichel | © 2nd Sight Lab 2023

About Teri Radichel:
~~~~~~~~~~~~~~~~~~~~
⭐️ Author: Cybersecurity Books
⭐️ Presentations: Presentations by Teri Radichel
⭐️ Recognition: SANS Award, AWS Security Hero, IANS Faculty
⭐️ Certifications: SANS ~ GSE 240
⭐️ Education: BA Business, Master of Software Engineering, Master of Infosec
⭐️ Company: Penetration Tests, Assessments, Phone Consulting ~ 2nd Sight Lab
Need Help With Cybersecurity, Cloud, or Application Security?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
🔒 Request a penetration test or security assessment
🔒 Schedule a consulting call
🔒 Cybersecurity Speaker for Presentation
Follow for more stories like this:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
❤️ Sign Up my Medium Email List
❤️ Twitter: @teriradichel
❤️ LinkedIn: https://www.linkedin.com/in/teriradichel
❤️ Mastodon: @teriradichel@infosec.exchange
❤️ Facebook: 2nd Sight Lab
❤️ YouTube: @2ndsightlab
Sed
File Manipulation
Commands
Command Line
Replace String
Recommended from ReadMedium