Hot answers tagged

7

awk -F '= ' '/CURRENT_PROJECT_VERSION/{$2=$2+1";"}1' OFS='= ' input > output Tests cat file SOME_DUMMY_VALUE = -1; CURRENT_PROJECT_VERSION = 4; SOME_SECOND_DUMMY_VALUE = -1; CURRENT_PROJECT_VERSION = 4; awk -F '= ' '/CURRENT_PROJECT_VERSION/{$2=$2+1";"}1' OFS='= ' file SOME_DUMMY_VALUE = -1; CURRENT_PROJECT_VERSION = 5; SOME_SECOND_DUMMY_VALUE = -1; ...


5

Unix does not have file-name-extensions, nor does Microsoft's Windows (not after Windows ME. However file-explorer still has the concept). What you need to do is find all files starting with ... (in your case starting with cheatsheetold.. You can do this with cheatsheetold.*. It will then pass the file list to rm. You can use it with any command. It is not ...


5

The following awk program should work. It looks for ( ... ) elements in each line and checks if they fit the "author(s), year" or "author(s)1 year1, author(s)2 year2, ..." pattern. If so, it creates a citation command and replaces the ( ... ) group; otherwise it leaves the group as it is. #!/usr/bin/awk -f # This small function creates an 'authorYYYY'-...


5

alias in bash are not designed to take arguments and won't know to what to do with it if provided with one. They should generally be avoided and should only be used for really simple command name alternatives. Recommend using a function instead. Note that pgrep is a valid Linux binary which shouldn't be used, recommend using a non ambiguous name instead. ...


3

Out of the box many *nix terminals allow copying and pasting text by simply selecting the text you want to copy, and inserting it by pressing the middle mouse button. No additional button presses needed! If that is not a UX improvement, I don't know what is. Generally speaking, you can swap the Control and Command buttons yourself by using built-in tools ...


3

Another answer, using only awk. This assumes that you adhere to the key <space> = <space> value; syntax throughout: awk '$1 == "CURRENT_PROJECT_VERSION" {$3=($3+1)";"}1' testfile.txt This increases the third field by 1 in all lines starting with CURRENT_PROJECT_NUMBER but otherwise prints all lines "as is" (this is the meaning of the 1 behind ...


3

grep ".\{0,81\}" foo.txt Any line will match this. If line has 82 characters, it also has 81 characters. You need to either: wrap the regex in ^ and $ so that, from start of line to end of line, there are between 0 and 81 characters, or use -x to specify that the line must exactly match this regex (equivalent to the above option) So: grep "^.\{0,81\}$" ...


2

This should be part of your terminal. You can just map copy to Ctrl+C though in doing so you will likely lose the ability to insert ^C with a shortcut. Since keybinding are associated with individual applications I doubt you will find a solution that will cover everything system wide. I believe you would need to change it in the setting of all programs.


2

If filename.sh contains the definition of unload_proxy, then you need to use source ./filename.sh or the shortcut . ./filename.sh. Sourcing the file causes it to evaluate within the current shell's environment, thereby letting it define new functions. in your example, you're running the file directly* (ie without sourcing), and the sequence of events is as ...


2

With perl, modifying the file in-place: perl -pi -e 's/\bCURRENT_PROJECT_VERSION\s*=\s*\K-?\d+/$& + 1/ge' test.txt


2

With sed and bash: FILE="test.txt" REGEX="\(CURRENT_PROJECT_VERSION *= *\)\([0-9]\+\);" version=$(sed -ne "s/${REGEX}/\2/p" ${FILE} | head -1) ((version++)) sed -ie "s/${REGEX}/\1${version};/" ${FILE}


2

Note that pcregrep (from the PCRE library) and GNU grep -P (when built with PCRE support) can take perl-like regular expressions and grep -P will work OK on UTF-8 data when in UTF-8 locales. If you wanted to use perl instead, you could define a script or function to do so. Aliases won't do as aliases are just aliases, just meant to replace one string with ...


2

It was not stated in which shell (bash, fish, zsh, csh) you desire to use some sort of wildcard when removing files. As bash is a prominent shell I state that it would be possible to simply use this command: rm -- cheatsheetold.* note that the wildcard * is used after the -- as to avoid any unindented mishaps by bash shell extensions the command line ...


2

Sounds like you want it to run when you log into the Mac and not when you start Terminal. You can add the script to: System Preferences -> Users & Groups -> Login Items


2

The place to find the open source components of MacOS is https://opensource.apple.com/ , and the package where arch is included is called system_cmds. Unfortunately, the links for Catalina (10.15.x) seem to be unavailable at the time of writing this (this is not uncommon, because Apple usually publishes the source with some delay). The version you want is ...


2

!(pattern) is a ksh glob operator. shopt is a builtin command of the bash shell to enable one of its options (the ones that are not enabled with set -o). bash's extglob option enables a subset of ksh extended glob operators. In zsh, negation is with the ^ extendedglob operator as @mdmay74 has already shown and zsh has only one set of options all toggled ...


2

Try this, sed -n '/word/{n;p;q}' file n -> Read/append the next line of input into the pattern space. p -> Print the current pattern space. q -> Immediately quit the sed script without processing any more input, for only first occurrence...


2

Just a slight adjustment to the first sed operation should do it: sed -n '/PAT1/,/PAT2/{/^x [[:digit:]]*/p;}' file.txt > newfile.txt There's probably no need to try excluding PAT1 & PAT2, unless they occur in the same line as ^x [0-9] If this is the case: sed -n '/PAT1/,/PAT2/{/PAT1\|PAT2/!{/^x [0-9]*/p;};}' file.txt will also exclude PAT1 & ...


2

You have to use double quotes to get variable expansion. To print literal double quotes inside double quotes you have to escape them: osascript -e "display notification \"${RSYNC1}\" with title \"Backup\"" Alternatively, use single quotes when inside the double quotes: osascript -e "display notification '${RSYNC1}' with title 'Backup'"


1

Another awk variant, just make PAT2 the record separator RS, PAT1 the field separator FS and print the last field NF, making sure that the output is not the result of a repetition of RS awk 'BEGIN{RS="PAT2"; FS="PAT1"}NF>1{print $NF}' file1 This is the text that I want to get This is another text that I want to get DONE


1

If you want to keep your simple approach and folders, you can separate by number of digits: for d in ?/; do echo "$d"; (cd "$d" && ls); done for d in ??/; do echo "$d"; (cd "$d" && ls); done This duplication of code is of course not very nice. But then again, you give no context at all, except "you must #1 #2 #3". Or maybe: for d in {1....


1

They are in alphabetical order. In alphabetical order, 2 comes after 10 because 2 comes after 1, just like B comes after AB. Here you want a numerical order instead of an alphabetical order. To do that, make sure you use the zsh shell (should be the default user shell in the latest version of macos) and use: for d in *(N/n); do (cd -- $d && print -...


1

The back-reference \1 is missing the corresponding subexpression: sed -n -e 's/^.*\(Word1 word2\)/\1/p' file1.txt > newfile.txt The brackets group together Word1 word2 so that it can be used as \1 in the replacement If the -E (--regexp-extended) option were used, the brackets wouldn't require the preceding \ Also note that this actually deletes all text ...


1

In the link that you referenced, reading the accepted answer there: in the comments that follow it, one person asks what the equivalent is for zsh, and @MrT responds with: setopt extendedglob to set the extended glob mode in zsh. ^ is the exclusion symbol, so mv ^new new would do the trick. then to see all the options set in zsh you can use setopt and to ...


1

I don't know about low-level differences in MAC-OS vs Gnu/Linux. However: For all systems using X11 (just about all Unixes except MacOs), there are various X11 libraries. For a wide range of systems (including Gnu/Linux and Microsoft's Windows, MacOs, android, iOS), there is SDL. A cross-platform platform for graphics, keyboard, mouse. It is often used to ...


1

You can do that. Both John accounts need the same UID. Look for the UID in the old machine (in /etc/passwd 1st field with numbers after john) and then set up the new computer with john and the same UID. Say we found john had uid 1234 on the old computer. to add the user john with ID 1234 to the new computer useradd -u 1234 -c "John The Ripper" john The ...


1

You can use the wildcard, but you got to be very careful as it can delete other files that may match. rm cheatsheetold.* The command above will delete any file whose name starts with cheatsheetold. and is followed by anything, so any extension.


1

file.txt | less -R The -R option on less (or more) allows ANSI characters to be interpreted.


1

The OP wants to see the output as well, so we need a small script #!/bin/bash exec 3>&1 # Make a copy of the stdout fd on fd 3 while "/Applications/Adobe After Effects 2020/aerender" -project "/Volumes/Videos/Test.aep" -sound ON | tee /dev/fd/3 | grep 'WARNING:After Effects warning' >/dev/null do echo "Repeating the command" done ...


1

Here is a simple test : ~/tmp$ printf "\x1Aabc\r\n" > test ~/tmp$ od -a test 0000000 sub a b c cr nl 0000006 ~/tmp$ dos2unix test dos2unix: Binary symbol 0x1A found at line 1 dos2unix: Skipping binary file test ~/tmp$ dos2unix -f test dos2unix: converting file test to Unix format... ~/tmp$ od -a test ...


Only top voted, non community-wiki answers of a minimum length are eligible