I am trying to read some comma-separated data from a text file, parse it and calculate average of column-5. The input is in the following form: I am using the following script for this: The problem with the script is that it does not read / parse the last line of the text. What can I do about that? Also,
Tag: shell
Bash script does not wait for user to enter response
I am trying to read a text file (line by line) and take user response in a while loop. However, the script does not wait to take input. Instead, it just prints all the text to screen. The script only prints alternate text lines from the file (Please refer to the image below). Output Answer This worked for me:
Bash escape character
I have this very reduced example of a bash command, where I want the $ sign escaped. So the command : should print out: a simple $test does not work unfortunately. I tried lots of other stuff but still couldn’t find a solution. Any suggestions ? Answer Put it in single quotes rather than double quotes. The single quotes keep
How to get audio length for all audios using sox?
I can do soxi -d * to get audio length information in hours, minutes, and seconds. However it would only give me info on the individual audio length. If I wanted to see the audio length for the entire folder, how can I accomplish such task? like when you do “wc -w” it shows the sum of everything at the
Move a file and rename it if the destination folder contains also a file with the same name
Sorry for my bad english. I want to move a file from the Desktop to user’s input destination. If destination has also a file with the same name, how can i ask user to rename the file so that he can have them both in destination folder? I have this right now: Answer Demonstrating using mv and switches -i (interactive)
using grep commands to find a duplicate id within a json file
I am looking for a way to use grep on a linux server to find duplicate json records, is it possible to have a grep to search for duplicate id’s in the example below ? so the grep would return: 01 Answer OK, discarding any whitespace from the JSON strings I can offer this if awk is acceptable – hutch
Executing bash shell script accepting argument and running in background
I have written a shell script run.sh to trigger a few tasks based on the user’s input The tasks 1,2 … 6 are php scripts that are run like /usr/bin/php task1.php $TIME with $TIME as an argument for the php script etc… The script runs fine when I type bash run.sh but since tasks 1-6 takes a long time to
Bash – How can i send notification once if a service is not running?
I am running the following script to check if my docker services are running. If a service isn’t running, the script sent a message to my rocketchat app via webhook like this: It works, but if a docker service is not running, i receive the message every minute again, because the script is running every minute via cronjob. So how
How to add number assigned as array
I have that script that is supposed to read data from two txt files and add them. For that matter I have used array. I can read the data but there is a problem with the addition. Instead of ${dataAll[$i]}= $( ${data1[$i]}+${data2[$i]} ), I have also used ‘expr ${data1[$i]}+${data2[$i]}’ The analysisSBM105.out file has the following But still it doesn’t work.
Why print empty path in shell script?
samuel@:~/…/linux$ ./test.sh find . -type f -name “*” samuel@:~/…/linux$ How do I fix this to get find . -type f -name “*” ‘s result? Answer I suggest to use an array: