New answers tagged

6

As you are already using awk and are looking for a simple solution: awk -F/ '{n=split($3, a, "."); printf("%s.%s", a[n-1], a[n])}' <<< 'http://www.example.com/index.php' ^ ^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^ | | | | | | | last two ...


4

Parsing URLs with Bash The following questions should provide a good starting point: Parse URL in shell script Parse below URL in bash @pjz's answer breaks apart a URL into more manageable parts: #!/bin/sh INPUT_URL="https://www.amazon.com/gp/product/B007B60SCG/ref=ox_sc_act_title_1?smid=ATVPDKIKX0DER&psc=1" # extract the protocol proto="`echo $...


1

It's not required that you declare your array upfront, but if you do, you need to use the lower case "a"; not the capital. declare -a listofnames Secondly, you need to use numerical indicies when referencing an array element listofnames[one] <----- incorrect listofnames[1] <----- correct So, for your two elements, it should look like this: ...


-1

I've looked into this question as well, and it appears that the "Data Added" attribute (kMDItemDateAdded) can be queried from mdls (but not xattr), but cannot be set. There is no option for it in the setattrlist function. The comments on this SO question go into a little (but not much) more detail. The "Date Added" value appears to be derived from some other ...


1

It looks like do shell script is running the script under the sh shell, which is actually bash in compatibility mode; in this mode, the builtin echo command apparently thinks it needs to interpret some escape (backslash) sequences. This is one of several features of echo that aren't consistent between versions/modes/etc; as the POSIX standard for echo says, "...


0

@nohillside 's answer above is great actually. The only issue with it is that it does not account for files with spaces in them. That will cause some of the commands to fail. So I'm putting an answer here that would support that as well. This will just echo out the mv commands: find . -type f -exec sh -c 'for f do x=${f#./}; y="${x// /_}"; echo "mv ${x// /...


1

There's no default ps binary installed in /usr/local/bin. It is installed in /bin. What happens here is that your /usr/local/bin/ps program seems to take precedence over your /bin/ps program because of your PATH settings. In order to fix the problem, just delete your newly created shortcut in /usr/local/bin/ps. When you delete the file, the system should ...


1

You need to temporarily disable System Integrity Protection https://www.howtogeek.com/230424/how-to-disable-system-integrity-protection-on-a-mac-and-why-you-shouldnt/


0

take into account only .mov, .mp4 and .mxf files I modified the above script by Gordon Davisson. https://apple.stackexchange.com/a/363864/44531 This may need modification. I didn't understand the -locationpath option. I do not have compressor, so I merely echo the last line. Set debug to false when you get tired of the output. I no longer w-...


4

I don't have Compressor.app to test with, but this should work: fileargs=() for d in "$@" do [ -f "$d" ] || continue filename=$(basename "$d") fname="$(dirname "$d")"/"${filename%.*}" fileargs+=(-jobpath "$d" -settingpath /Applications/Compressor.app/Contents/Resources/Settings/ProRes/proResHQName.setting -locationpath "$fname".mov) done /...


2

I prefer using fc since that's my Korn shell (ksh) to get to my editor and that should choose vim by default since they go together more naturally than the emacs command. For changing the editor, I usually set FCEDIT so that it catches both the bash / emacs invocation for the fc built in commands. I rarely change things, though since it's nice to know I can ...


11

Simply set the EDITOR variable to vim in your bash startup file. EDITOR=vim From the bash manual edit-and-execute-command (C-xC-e) Invoke an editor on the current command line, and execute the result as shell commands. Bash attempts to invoke $FCEDIT, $EDITOR, and emacs as the editor, in that order.


0

This method works only if you saved the bash_profile file to a point where you want to go back in TextEdit, doesn't work if edited using vi or nano (thanks to @nohillside for pointing this out). You can open the file using TextEdit (for ex: open ~/.bash_profile) and click on File -> Revert To -> Browse All Versions... and then select the version you ...


2

My understanding is that you send a script to your remote systems. You then run the script. I'm not sure what user id the script will be run under. I don't know what you want to do for that user. You could put the following header code in a script. It figures out if the user is an admin user or a non admin user. There are many ways to check for admin. ...


3

The following is a proof of concept to show how I'd build out the target_directory and target_filename from the source_filename, based on information in your OP and comments: $ ls -1 DSC_0008.JPG DSC_0034.JPG DSC_0077.JPG DSC_0132.JPG codetest $ cat codetest #!/bin/bash find . -type f -iname '*.jpg' -size +500k -exec sh -c ' i=7398 for f in "$@"; do m=...


2

This works for me with bsd sed- echo "I am a jelly donut" | sed 's/./\\&/g' \I\ \a\m\ \a\ \j\e\l\l\y\ \d\o\n\u\t and with your string echo 'Example string 59^!#&$(' | sed 's/./\\&/g' \E\x\a\m\p\l\e\ \s\t\r\i\n\g\ \5\9\^\!\#\&\$\(


-1

One approach is to define your prompt in your .bashrc- #sudo -s in .bashrc case $LOGNAME in root) PS1="\e[0;31m[\u@\h \W]\$ \e[m " ;; *) PS1="\h:\W \u\$ " ;; esac and place the following in your .bash_profile- case $- in *i*) . ~/.bashrc ;; esac This will source .bashrc if your shell is a login interactive shell, otherwise .bashrc ...


1

You should expect that any csv file will need to be sanitized before using it in the shell environment. At minimum, the header, if it exists, should be removed, all line terminating characters will need to be converted to LF (the linefeed character), and the last line of the csv file will need to be terminated. The file command shows that your csv file has ...


1

On shell level while IFS=\, read -t $'\r' s t; do echo mv -n "$s" "$t/" done < orderfile.csv Remove the echo once you are sure the result looks ok. As a small safeguard against errors I would recommend to limit a CSV to about 1000 lines.


2

There are many ways to tackle this task. Below is an approach using the Go language. I expect others will soon be along with alternative tools and languages. If this is a one-time task, expect to spend time handholding the process. If this going to become a regular automated task, spend time now to get the script or tool right. Things to be aware of: ...


0

This one is working for me, pkill Electron or pkill Visual Studio Code


Top 50 recent answers are included