Shell
Shell Script – Add strings to the beginning of files
Here is a shell script to find all txt files and add string “my_begin” to the beginning of files.You can change the string for your target.
Here is a shell script to find all txt files and add string “my_begin” to the beginning of files.You can change the string for your target.
Here are some folders which contain json files.These json files have a version value, just look like the following image. We will increase this number by 10 for every json file in current folders recursively.Install command line tool jq to modify json file easily.Ubuntu: sudo apt-get install jqWindows: just download exe on the Read more…
It failed to convert markdown to pdf file by pondoc on my CentOS8 server.I installed all missing components about texlive. But pandoc could’t find Chinese characters to generate complete PDF file. So I downloaded Chinese font file and install it.You can find source file on some font website such as https://chinesefonts.org/.Put Read more…
Let’s write a shell script example to make note about how to find the first occurrence position and the last occurrence position of substring in string. Output:
When you use php to execute shell script to handle file, the filename may have to be preprocessing due to a few special characters. It’s better to set character encoding before running shell command.
In DOS/Windows text files a line break, also known as newline, is a combination of two characters: a Carriage Return (CR) followed by a Line Feed (LF). In Unix text files a line break is a single character: the Line Feed (LF).You can use cat -A fileName to check if there is ^M$ in Read more…
In the following example, we will create a function to compute number’s factorial result.Let’s echo in the function to support fetch return value outside. Output:
If you have a few zip files in a folder, and the zip file had compressed some child zips, the following shell script can help you to extract them. The compressed information in our example look like: Shell script: #! /usr/bin/bash # find zips in current path files=() find . Read more…
Rename Files’ Suffixes Recursively And Find Folders Find Folders To find all folders in the current path, I wrote a simple shell script file. It ignores invisible folder which path looks like ./.XXX. #! /usr/bin/bash dirs=() find . -type d -print0 >tmpfile while IFS= read -r -d $’\0′; do dirs+=(“$REPLY”) Read more…