The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,045 other followers

Archive for the ‘sed’ Category

Audacity error when starting “The application “Audacity.app” can’t be opened.”

Posted by jpluimers on 2020/06/29

For quite a while, I had the error “The application “Audacity.app” can’t be opened.” and Audacity still opening. Clicking the OK button often enough made me hunt for the solution:

This is what I did:

$ cd ~/Library/Application\ Support/audacity
$ grep Temp audacity.cfg
TempDir=/Users/jeroenp/Library/Application Support/audacity/SessionData

Then I checked if the directory existed:

$ find ~/Library/Application\ Support/audacity -type d
/Users/jeroenp/Library/Application Support/audacity
/Users/jeroenp/Library/Application Support/audacity/AutoSave
/Users/jeroenp/Library/Application Support/audacity/Plug-Ins
/Users/jeroenp/Library/Application Support/audacity/SessionData

The odd thing is the directory already existed, so I decided to delete the line, but first needed sed -n (the -n is important: it list only non-matching lines to stdout, see [WayBack] regex – What actually the meaning of “-n” in sed? – Stack Overflow):

$ sed -n '/^TempDir=/p' ~/Library/Application\ Support/audacity/audacity.cfg
TempDir=/Users/jeroenp/Library/Application Support/audacity/SessionData

Since this is Mac OS/Mac OS X/OS X, the -i parameter requires a string even if it is an empty [WayBack] shell – Delete lines in a text file that contain a specific string – Stack Overflow so we get:

$ sed -i '' -n '/^TempDir=/d' ~/Library/Application\ Support/audacity/audacity.cfg

After that, starting audacity still gave the same error and the TempDir entry was re-added.

So I did this:

  1. renamed the audacity directory to audacity.bad,
  2. recreated an empty audacity directory
  3. created empty subdirectories AutoSave, Plug-Ins, SessionData
  4. looped this loop
    1. Start Audacity
    2. On success copy a missing file in the audacity directory tree from the audacity.bad directory tree

In the end, these files were the cause:

  • pluginregistry.cfg
  • pluginsettings.cfg

Since I wasn’t using any plugins, I removed them. Now audacity starts fine.

Now that I had the files pinpointed, I could refine the search and this seems to be a common problem [WayBack] FAQ:Installation, Startup and Plug-ins – Audacity Development Manual: How can I solve Audacity not appearing or crashing on launch, or crashing after I add a plug-in?.

Too bad that page didn’t show up in the original search results.

–jeroen

Posted in *nix, *nix-tools, Apple, Mac, Mac OS X / OS X / MacOS, MacBook, MacBook Retina, MacBook-Air, MacBook-Pro, Power User, sed | Leave a Comment »

bash + sed: quadruple backslash for proper escaping within an alias

Posted by jpluimers on 2020/06/09

This is part of a bash alias where I had to use quadruple backslash in order to escape it for sed:

# The sed with quad //// is to prevent 'unterminated substitute in regular expression':
alias x='... | sed "s/=.*/ \\\\/"'

This is needed because bash will escape \\\\ into \\ which sed then escapes to \.

The easiest way to find this is to replace the sed with echo to see the expansion.

References:

–jeroen

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, sed, Software Development | 2 Comments »

Linux command shows a list of all subdirectories that contain a least one .xml file – Thomas Mueller

Posted by jpluimers on 2019/09/09

Via [WayBack] So I don’t forget: The following Linux command shows a list of all subdirectories that contain a least one .xml file… – Thomas Mueller (dummzeuch) – Google+:

[WayBack]Find all subdirectories containing xml files on Linux command line

find . -type f -name '*.xml' | sed -r 's|/[^/]+$||' | sort | uniq

The sed bit is explained in [WayBack] Get list of subdirectories which contain a file matching a string:

The sed command consists of a single substitute. It looks for matches to the regular expression /[^/]+$ and replaces anything matching that with nothing. The dollar sign means the end of the line. [^/]+' means one or more characters that are not slashes. Thus, /[^/]+$ means all characters from the final slash to the end of the line. In other words, this matches the file name at the end of the full path. Thus, the sed command removes the file name, leaving unchanged the name of directory that the file was in.

–jeroen

Posted in *nix, *nix-tools, Power User, sed, sort, uniq | Leave a Comment »

sed in a bash script: backslash escape anything that looks suspicious

Posted by jpluimers on 2019/02/26

Did I ever tell I dislike regular expressions and old-skool shells?

They’re not good for anything but basic commands, so if you try any scripts in them, you’re basically lost.

If you disagree, please read [WayBack] Don’t write Shell scripts. I would recommend Python, but I tried “pip search mysql”…. – Kristian Köhntopp – Google+) and [WayBack] How did this shit ever work? by the same author.

On the other hand: on many system, the baseline isn’t much more than a shell and a very limited tool set.

With nx like systems that usually comes down to sed and a shell like bash.

Since I wanted to modify an openssh hardening script to cover more permutations that was using sed in a bash script, I had not much choice but to bite the bullet.

TL;DR:

When you use any of the below characters, prepend them with a backslash as they have a bash meaning in addition to a sed meaning.

  • ? becomes \?
  • ( becomes \(
  • ) becomes \)
  • | becomes \|

The script

Hopefully by now it’s [Archive.is] been merged into https://github.com/comotion/gone/blob/github/modules/ssh. If not, it’s at https://github.com/jpluimers/gone/blob/jpluimers-ssh-hardening-patch/modules/ssh.

The diff: [Archive.is] https://github.com/jpluimers/gone/commit/329bf12a320704080e68eee90f4c099e92d8388d?diff=unified

The relevant portion (which also uses backslashes as line continuation and wrap a command over multiple lines [WayBack]):

sed -i \
-e 's/#\?MaxAuthTries *[0-9]*.*/MaxAuthTries 2/' \
-e 's/#\?PermitRootLogin *\(yes\|no\).*/PermitRootLogin no/' \
-e 's/#\?UsePrivilegeSeparation *\(yes\|no\|sandbox\).*/UsePrivilegeSeparation sandbox/' \
-e 's/#\?StrictModes *\(yes\|no\).*/StrictModes yes/' \
-e 's/#\?IgnoreRhosts *\(yes\|no\).*/IgnoreRhosts yes/' \
-e 's/#\?PermitEmptyPasswords *\(yes\|no\).*/PermitEmptyPasswords no/' \
-e 's/#\?ChallengeResponseAuthentication *\(yes\|no\).*/ChallengeResponseAuthentication yes/' \
-e 's/#\?KerberosAuthentication *\(yes\|no\).*/KerberosAuthentication no/' \
-e 's/#\?GSSAPIAuthentication *\(yes\|no\).*/GSSAPIAuthentication no/' \
-e 's/#\?GatewayPorts *\(yes\|no\).*/GatewayPorts no/' \
-e 's/#\?X11Forwarding *\(yes\|no\).*/X11Forwarding no/' \
-e 's/#\?PrintMotd *\(yes\|no\).*/PrintMotd no/' \
-e 's/#\?PrintLastLog *\(yes\|no\).*/PrintLastLog yes/' \
-e 's/#\?TCPKeepAlive *\(yes\|no\).*/TCPKeepAlive no/' \
-e 's/#\?PermitUserEnvironment *\(yes\|no\).*/PermitUserEnvironment no/' \
-e 's/^\(HostKey .*ssh_host_dsa_key\)/#\1/' \
sshd_config

–jeroen

 

 

 

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, sed, sed script, Software Development | Leave a Comment »

15 Useful ‘sed’ Command Tips and Tricks for Daily Linux System Administration Tasks

Posted by jpluimers on 2017/10/06

In this article we will review sed, the well-known stream editor, and share 15 tips to use it in order to accomplish the goals mentioned earlier, and more.

I like it because 15 Useful ‘sed’ Command Tips and Tricks for Daily Linux System Administration Tasks has a lot of screenshots showing what each expression actually does.

–jeroen

Posted in *nix, *nix-tools, Power User, sed | Leave a Comment »

 
%d bloggers like this: