I want to compare the number of lines of each file and choose the one that contains the maximum number of lines for example I will get as result Answer Alternative with lot’s of piping this script assumes the file names are under your control and space or _V won’t appear in the base names. Otherwi…
Tag: bash
How to run eval spawn ssh and expect in background?
I created a script to get in inside an Access Point (AP) using ssh and execute some commands and I used expect to interact with shell. The scripts works fine when it is running on foreground, but when I try to execute the same script in background using & to fork the process, it stop at spawn ssh command …
Centos shell script – Group files starting with the same string
I have a directory with many pdf files. Each file name starts with a numeric ID (5 chars fixed length), as follows: I’m trying to figure out how to write a shell script in CentOS that reads files in such directory and list them depending on the ID. The shell script should return the following output (on…
Bash script to check a specific php process is running?
I am running websocket server with the nohup command like below. But it stop working after few hours.So i have created a bash script like below Then i run the script with below command like below. The work of the above script if to check my chat-server.php is running or not if it is not running then it will s…
Function Shell Script no return data
When i run the script (./meuscript.sh), I have no return, only if i select cancel the dialog. If I run the script without the function, the command is executed correctly Answer You have an endless loop. Rename the function to something else so that you don’t end up with ping calling ping calling ping ca…
Bash – one-liner echo with delimiter
So my sample code so far looks like this: I want to be able to echo it out to make it look like the following: But the problem is that when I tried using AWK, sed, or IFS they also use n as delimiters which I don’t want that to happen as the text gets all messed up. Is there
SED one liner to uncomment and replace first occurrence of a pattern
I have this settings.conf file in linux defined as follows: I would like to uncomment # second-setting = off of Section A only (first occurrence), and set the value to on. So far, I have this: cat settings.conf | sed ‘/^# second.*/ {s/^#//;s/off/on/}’ Any tips? Answer Is this what you had in mind?…
bgzip all VCF files in a directory?
So I’ve been trying to bgzip around 100 VCF files in parallel, but although the jobs are submitted and files get created there’s definitely something wrong. So far I’ve been trying: What is the correct way to do this? Thanks in advance! Answer If, as my websearches suggest, bgzip works the s…
How to list recently deleted files from a directory?
I’m not even sure if this is easily possible, but I would like to list the files that were recently deleted from a directory, recursively if possible. I’m looking for a solution that does not require the creation of a temporary file containing a snapshot of the original directory structure against…
Parsing a config file inside shell script
I am trying to parse an ini file inside a shell script. name.conf file: I could parse the values by the command I wanted to know if there was some way by which I could group the contents of my config and parse it name.conf file: I just need the values in a shell array say names and print them