I want to get the hexadecimal value of 你, someone tell me to use printf “%x” “‘你”, but I don’t know what’s the function of ‘ in printf “%x” “‘你”, why use ‘ before 你? Answer From the bash manual: Arguments to non-string format …
Tag: bash
Provide windows avilable cores
I use the following in my script to find how many available cores I can use. This is for Linux: This is for Mac (darwin): How should it be in Windows? Answer You can use one of those commands: (here you have two physical processors) Or as suggested in comments: In Makefile the record should be something like:…
Using sed (or any other tool) to remove the quotes in a json file
I have a json file I want to change it to i.e. convert the requestId from String to Integer. I have tried some ways, but none seem to work : Could someone help me out please? Answer Try or The main differences with your attempts are: Your regular expressions were looking for [0-9] between double quotes, and t…
What is efficient way to ensure bash script variable is valid permission bits?
I’m inexperienced with bash scripts, mostly cobbling things together from google searches. The following simple script creates file foo and changes its permission bits to whatever the script’s $1 is. Can an experienced bash scripter please advise what would be a proper and/or efficient way to ensu…
Symbolic Link Edits and differences to hard link [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack …
Remove newline before a match – Linux
I want to remove the newline before the </script> in my HTML file with a Linux command (sed, awk…). Sample input: Sample output: I tried different syntax, but none of them could do. Answer First of all, as mentioned in the comments Don’t parse XML with Regex! Never do it, never think about i…
How to grep within a loop to exclude?
I have a NPM_RESERVED_SCOPE that contains a comma-separated list of forbidden scope. I have a NPM_ALLOWED_DEV_DEPENDENCIES_PACKAGES that contains a comma-separated list of exception. I want this script to passe if the devDependencies does not contains any of the NPM_RESERVED_SCOPES, except the list of excepti…
Fast way to grep gzipped files in reverse piped to tail/head
I need to search a folder of gzipped files for a string, however I need to search starting at the bottom of each file. I then need the command to return results when it has 10 matches. So far I have this: I’m using zcat to get all the file contents, and then I use tac to reverse them. This
Bash select multiple values in CSV column
I have the following CSV format: “/opt=920MB;4512;4917;0;4855″,”/=4244MB;5723;6041;0;6359″,”/tmp=408MB;998;1053;0;1109″,”/var=789MB;1673;1766;0;1859″,”/boot=53MB;656;692;0;729” I would like to extract 2 values from each column, the first and the last…
Copying multiple text lines into a file after specified pattern using shell [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago. Improve this question I want to insert multiple line from file1 marked with pattern into a file2 using shell. The …