Skip to content
Advertisement

Tag: bash

Sorting a file using fields with specific value

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

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):

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

Advertisement