Recently, I had to sort several files according to records’ ID; the catch was that there can be several types of records, and in each of those the field I had to use for sorting is on a different position. The fields, however, are easily identifiable thanks to key=value structure. To show a simple sample of the general structure: I
Tag: bash
Using conda activate or specifying python path in bash script?
I’m running some python scripts on some Linux clusters using SGE or SLURM. I already have my conda environment set up properly using the login node. I have been writing something like to activate the environment properly. (I have done a lot of work to figure this out) However, I just found some example codes like seems to do the
How to wrap color coded text to fixed line length in terminal?
For text with color codes, how to wrap it to a fixed length in the terminal? Text without color codes wraps nicely with fold: But this red text wraps wrong: Note: While the red text is wrapped wrong, it still is printed in red, which is the desired behavior. (My use case is line wrapping the output of git log
Linux find xargs command grep showing path and filename
find /folder/202205??/ -type f | xargs head -50| grep ‘^Starting’ There are 20220501 20220502 20220503 and so on folders… This command searches all first 50 lines of all files in ‘/folder/202205??/’ and shows the lines beginning with text “Starting” I haven’t the path and the filename of the files that are matched by the grep command. How can I get
Bash script conversion to fish
I’m trying to convert this script to fish: https://github.com/masahide/OmniSSHAgent/blob/main/hack/ubuntu-bash.setup.sh This is my progress so far: It should be fully converted except that main command substitution in the last function: that raises this error: And I don’t understand how to convert it. Can you help me? Thanks Answer Found the correct way to convert it (thanks to @masahide: https://github.com/masahide/OmniSSHAgent/issues/16#issuecomment-1107446991):
How to get difference between 2 dates (Z format) in milliseconds
Well I’m trying to get the difference between two dates in Seconds.MilliSeconds The dates are in Zulu format I have tried these two approaches doesn’t work out for me Is there any better way to get the difference in Seconds.MilliSeconds In linux for Z format time zones Answer Suggesting Output:
Bash: No such file or directory when running shell comands with node.js spawn on linux
I wrote the following web server in node.js using express and hbs that can run shell files, but I keep getting the following error when I type this url into a web browser linux username here is replaced with my linux username Contents of nodejs file: This is the contents of run.sh: Answer Hello, I don’t know why I decided
If grep value not found return an echo [korn shell]
I have an issue with this script. What I’m trying to do is there are 3 conditions: 1- i put a valid input that is found inside the file and it gives me the output 2- I put a wrong input that can’t be found inside the file and give me an output of “Value not Found” 3- I don’t
How echo grave accent symbol in bash
(_ is input, i think) Answer Escape the grave accent. It’s special to the shell and is one way (the archaic one) to do command substitution. As noted by @dave_thompson_085 an alternative is to use single quotes in lieu of the double quotes you used, or to specify the hexadecimal representation of the grace accent, by doing echo “x60”. You
Bash jq with dynamic name
I’m trying to create a script to read the return code from a json from a curl command. my curl command is: The json output is: How can read the value “http_httpCode#HTTP Code” if 1650468248 is a dynamic value? Answer You could use to_entries so you can use .value to target the ‘unknown’ key: Online demo Another approach by just