Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack …
Tag: bash
Filtering a Block
I have multiple blocks of the below pattern I want to extract a block with Particular ID and Particular Name. The output should display For example :- I wanted to do using grep, sed, awk Thanks. Answer This sed should work for you: But you’d better use an xml parser as xmllint or xmlstarlet to parse val…
How do I sort a list of files and concatenate the contents in bash?
This works: But when I try to sort the the filenames, remove the newline the list of filenames that are piped to cat look identical to the previous but sorted: However cat returns this error: Answer Your xargs statement is expecting null terminated entries. If your filenames or directories have spaces, then y…
Bash script to list all processes in the foreground process group of a terminal
How can I write a bash script to print out the PIDs of all processes in the foreground process group of a given terminal (which is different from the one in which I run the script)? I know that the C function tcgetpgrp can do the job, but I am wondering if there exist any command line utilities that can
Change output filename when running a command in a loop
I am using the Tracer software package (https://github.com/Teichlab/tracer). The program is invoked as followed: tracer assemble [options] <file_1> [<file_2>] <cell_name> <output_directory> The program runs on a single dataset and the output goes to /<output_directory>/<cell_n…
bash ls output to file when ls finds no results
i’m relative new to scripting in bash, and made the following script: At the end of the script, i don’t make a new MLSready file. When i execute the script, i expect to see the result of the latest ‘ls -l’ command in my logfile, however (because i didn’t create a new MLSready fil…
Environment variables from .bashrc not being loaded when sourced from terraform script
I have a script being run with terraform on an EC2 instance like so: I have some environment variables defined in the .bashrc of this instance that I would like this script to have access to. However, inside that script I put, as the first line, but the variables defined in .bashrc were still unset. What do I…
Simulating ENTER key and export another variable together in Linux bash
I should put ENTER key value as a shell input to avoid shell waiting for user input. I have learned that ‘echo’ implicitly has an ENTER value, so tried to run below command to accomplish my requirement. As I expected, I can see the OS prompt instead of seeing Shell wait the user input. However, I …
How can I make a ksh script terminate itself if any issues?
I have written a few ksh scripts, about 6 scripts. These are written to handle huge data files, something like 207 MB big. while running the script, sometimes it gets stuck and does not end. Human interruption is required. In production environment, I want it to run automatically, and should be able to end au…
Bash scripting check condition
I’m new to bash scripting and trying to write the following simple And this works as expected. But if I delete echo “some string’ it prints nothing: Why? Why does deleting echo some_string right after the condition checking breaks the function? Answer It is because the if-condition is execut…