I am working on a bash script and I got a list of IP’s that I wanted to add one by one in a CURL command. For example given list on a file named list.txt I wanted to add each value on curl command Where $ARRAYVALUE is the IP address to be used on the command. I will appreciate any
Tag: bash
Looking to remove a set of characters from a .txt file
I am looking for a way to remove the content from one .txt file based on the other. For example, I have a file.txt with 2000 character that are random and not sorted. I have another file importantfile.txt with 2016 characters that have the same characters that file.txt has as well as 16 other characters rando…
Only accept 4 character long, decimal numbers as user input for read
I am writing a small script to easily capture weights, which are taken from user input with read -p. I want all captured weights to be 4 characters long, decimal numbers in the format XX.X. For example 30.2 kg. How can I make sure users can only input decimal numbers in that format? Thank you for your help. A…
Linux script to check if DNS have the same IP like the one next to it in the same list
I’ve got a list of DNS and IP adresses in this format: DNS IP DNS IP DNS IP And I need to do a script which do dig +short DNS and check if it has the same IP as the one next to it, and that with all the document. The idea is that if it’s the same, it returns
How to get fully interactive bash terminal in C with shift + ctrl keys?
I want to know how to create a fully interactive terminal. I am creating an interactive bash terminal like this: I can then go on to use read()/write() to send commands and receive output. My problem is how do I automate CTRL & SHIFT keys? Python’s subprocess does this so it’s definitely possi…
Why I get an error when I try to execute a command remotely?
I have a problem about execute command remotely via SSH. I am trying below. It gives an error like: Answer The problem is that you’re using double quotes to delimit the argument to ssh and also the argument to psql inside the command. This is causing your strings to be parsed incorrectly. You’re a…
How To Replace Strings With X to Y Characters
I have data similar to the following: I am looking for a way to replace strings in field 2. If the number does not have 10-11 characters, I would like to replace it with 12223334444 so the output would be: My original thought was to use cut to get the second field and then use grep “[1-9]” or some…
how to create a linux shell alias to give to g++ compiler the path of the file to compile?
What I want to do it’s to create an alias for the sentence below: Because I have to compile single files frequently. To do it, I’m trying creating a txt file with the output file name and the path of the file to compile. So I have a txt, called tocompile.txt, file that contains: then, I assign to …
Script terminates when storing grep -c output when value is 0
I am trying to check if a file has CR line feed and store the result 0 or 1 into a variable. Here is my command that runs inside a script. The script runs until the previous line and doesn’t run this line but terminates abruptly. Inside an echo statement it works perfectly. This prints isCR=0 or isCR=1 …
alias with bash involving current system time
I have the problem with macOS mojave, but I guess it generalizes to all bash environment. In the .bashrc or .profile, I add one line as: My purpose is to send the current system time as a message when commiting a change by typing gc. However, the system time was read when alias was invoked (here is when I log