Remove Unicode characters from textfiles – sed , other Bash/shell methods
Clear all non-ASCII characters of file.txt: $ iconv -c -f utf-8 -t ascii file.txt $ strings file.txt
Clear all non-ASCII characters of file.txt: $ iconv -c -f utf-8 -t ascii file.txt $ strings file.txt
Update: && and || have finally come to PowerShell (Core), namely in v7; see this answer. Many years after the question was first asked, let me summarize the state of affairs as of PowerShell v5.1: Bash’s / cmd‘s && and || control operators have NO PowerShell equivalents, and since you cannot define custom operators in … Read more
The “ is called Command Substitution and is equivalent to $() (parenthesis), while you are using ${} (curly braces). So all of these expressions are equal and mean “interpret the command placed inside”: joulesFinal=`echo $joules2 \* $cpu | bc` joulesFinal=$(echo $joules2 \* $cpu | bc) # v v # ( instead of { v # … Read more
Testing $? is an anti-pattern. if ./somecommand | grep -q ‘string’; then echo “matched” fi
This works for me sed ‘/^all:/ s/$/ anotherthing/’ file The first part is a pattern to find and the second part is an ordinary sed’s substitution using $ for the end of a line. If you want to change the file during the process, use -i option sed -i ‘/^all:/ s/$/ anotherthing/’ file Or you … Read more
How to do a loop against stdin and get result stored in a variable Under bash (and other shell also), when you pipe something to another command via |, you will implicitly create a fork, a subshell that is a child of current session. The subshell can’t affect current session’s environment. So this: TOTAL=0 printf … Read more
Bash doesn’t load your .bashrc unless it’s interactive. Run :set shellcmdflag=-ic to set it to interactive for the current session. To make the setting permanent, add set set shellcmdflag=-ic to the end of your .vimrc file. Use a bang (!) before sending a command to shell. For example: :! cd folder/.
Two simple solutions: Execute your code once before the while loop actions() { check_if_file_present # Do other stuff } actions #1st execution while [ current_time <= $cutoff ]; do actions # Loop execution done Or: while : ; do actions [[ current_time <= $cutoff ]] || break done
You could use awk for this. Change ‘$2’ to the nth column you want. awk -F “\”*,\”*” ‘{print $2}’ textfile.csv
With: FILES = $(shell ls) indented underneath all like that, it’s a build command. So this expands $(shell ls), then tries to run the command FILES …. If FILES is supposed to be a make variable, these variables need to be assigned outside the recipe portion, e.g.: FILES = $(shell ls) all: echo $(FILES) Of … Read more