New answers tagged

2 votes

How can I replace multiple substrings from multiple lines in a file matching a pattern from a different file?

We will use the ip_hostnames file to build a series of sed commands in the BRE regex syntax. These commands are basic s/ip/hostname/. Care is taken to escape the contents that go into the left hand ...
user avatar
  • 5,546
2 votes

How can I replace multiple substrings from multiple lines in a file matching a pattern from a different file?

Using any POSIX awk: $ cat tst.awk NR==FNR { map[$2] = $1 next } match($0,/([[:space:]]+([0-9]{1,3}\.){3}[0-9]{1,3})+$/) { path = substr($0,1,RSTART-1) $0 = substr($0,RSTART,RLENGTH) ...
user avatar
  • 23.5k
-1 votes

How can I replace multiple substrings from multiple lines in a file matching a pattern from a different file?

for i in $(cat ip_hostname.txt| awk '{print $2}') do cap=$(awk -v i="$i" '$NF==i{print $1}' ip_hostname.txt) sed -i "s/$i/$cap/g" path_ips.txt done output /path1/foo/bar host1 ...
user avatar
2 votes

How can I replace multiple substrings from multiple lines in a file matching a pattern from a different file?

This can be done entirely in sed, but the awk answer is generally more readable. #file toggle 1{x;s:^$:<IPs>:;x} /^EOF$/{x;s:<IPs>:<paths>:;x;d} #store hostname file x;/<IPs>/{...
user avatar
5 votes

How can I replace multiple substrings from multiple lines in a file matching a pattern from a different file?

The problem with your script is that you run a separate sed command for each IP address that is matched, which makes the script really slow when the file is big. You also have a nested loop, so you ...
user avatar
  • 2,997
0 votes

anybadge fails with: cannot import name 'get_template' from 'anybadge.templates'?

Known issue, somehow an anybadge update is causing the problem: https://github.com/jongracecox/anybadge/issues/63
user avatar
0 votes

Python programs suddenly get killed

It can be insufficient memory issue To find out it, you can use journalctl command jounalctl --since "1 hour ago"|grep killed jounalctl --since "1 hour ago" in anyway, just find ...
user avatar
0 votes

How to install specific version of python on Alpine linux

There are virtual environment software packages with features for installing and managing different versions of Python. Some can even install more than one version at a time and switch between ...
user avatar
  • 1,083
0 votes

How to install specific version of python on Alpine linux

You did not specify which tag you are using for the image from https://hub.docker.com/_/docker, but your question specifies Alpine so I will try to explain that. There is usually only one packaged ...
user avatar
1 vote

Defaulting to user installation because normal site-packages is not writeable

That behavior kind of makes sense: you should practically never install software into the system-wide site-packages using pip, as that will lead to conflicts with your system package manager, unless ...
user avatar
3 votes

python cannot find python in rhel8

In your interactive bash shell, python is resolved to python3 by an alias. Aliases are not inherited, so the /bin/sh sub-process can't resolve it. Although you could create a symbolic link so that ...
user avatar
0 votes

Cannot remove or fix python-cairo - Errors were encountered while processing: python-cairo:amd64

It seems that the symbolic link pyclean is broken. That happens often in a mixed python2/python3 environment. pyclean belongs to the package python2-minimal. So, this package should be uninstalled ...
user avatar
  • 164
1 vote

Passwordless ssh still asks for password when running as subprocess

I know this question has been asked 4 years ago but I faced the same problem and found an explanation and a solution which worked for me, so this might be helpful for other people in the same ...
user avatar
  • 11
1 vote

How do you list number of lines of every file in a directory in human readable format.

If you need only total lines from all files use grep find . -name '*.csv' | xargs wc -l | grep total This command works too wc -l *.csv | grep total
user avatar
0 votes

Parsing text using Python

Using Raku (formerly known as Perl_6) At the command line: ~$ raku -pe 's:g/ \{ .*? [ \} | $ ]//;' file OR ~$ raku -pe 's:g{ \{ .*? [ \} | $ ] } = "";' file Does it have to be Python? ...
user avatar
  • 1,456
1 vote
Accepted

Bulk replace multiple variables in multiple files at once

Split the problem into two parts: Iterate across the files Apply the substitution to a file If you are in the EXAMPLE directory you can loop across all the files like this for file in *.txt do ...
user avatar
  • 91.8k
0 votes

Find regex occurrances on block device (line length buffer issue)

Here is a solution using bash(1), grep(1), and perl(1): 1 #!/bin/bash 2 grep -P -a -b -o '#\d{10}(\000|$)' \ 3 | perl -ne '/(\d{10})/; print if 1635700000 <= $1 && $1 <= 1653699999'...
user avatar
2 votes
Accepted

Facing difficulties sending bytes containing white spaces python irc bot

The IRC protocol splits the messages into a command and a number of parameters, separated by whitespace. To allow for a trailing parameter that can contain whitespace itself, the protocol allows ...
user avatar
  • 119k
0 votes
Accepted

Change wallpaper every 10 minutes on Qtile

I've managed to implement this with this code snippet: import os import random from libqtile import qtile from typing import Callable from settings import WALLPAPERS_PATH class Timer(): def ...
user avatar
  • 143

Top 50 recent answers are included