How to print a line above the one with matching pattern in shell?

Bash
I want to print line 1 when the pattern match in line 2. For example - this is line 1 without pattern this is line 2 with random pattern When I do g...
3 years ago

Can't run shell script from other shell script

Bash
I'm trying to run a shell script that calls another shell script: #!/bin/sh for k in `cat ../config/file1.keywords` do echo "*** keyword: $k ***" ...
3 years ago

How to suppress I/O error message for BOTH terminal output and text log (tee)?

Bash
In my program, there will be a few seconds that the program writes data to a SSD that's not connected (i.e. writing to a empty bus host). As a result,...
3 years ago

unable to execute shell_exec() with variable

Bash
I'm trying to run shell_exec() with variable passed with AJAX from client. This code causes error (input file doesn't exist!): $searched_image = es...
3 years ago

How to exclude this / current / dot folder from find "type d"

Bash
find . -type d can be used to find all directories below some start point. But it returns the current directory (.) too, which may be undesired. How...
3 years ago

Redirecting file contents into another program in C

Bash
Making a basic shell and I need to handle file redirection. Specifically I am stumped on how I can feed data into a program like sort for example from...
3 years ago

Python command to wait for shell (ubuntu csh) finishing action / return code

Bash
I'm running a Python command + API to access ECMWF (European Centre for Medium range Weather Forecast) data server (called MARS) and download some fil...
3 years ago

Bash Shell Scrpiting, How can I write a script to run a program which ask for input?

Bash
I have a program, porodry, which will need read a parameters file to run, suppose the file called test1, so if I use bash I can run ./porodry term...
3 years ago

set variable on the same line as command

Bash
In sh programming I can do: dryrun="echo " ./myscript.sh And script uses it as: ${dryrun}ls -l (as an example) I can't seem to figure out how to...
3 years ago

How to display the longest line from user input

Bash
I have a shell script that need to ask the user for 4 lines of input. Then I need to display the longest line that was entered, and then whole input i...
3 years ago

Using sed to insert lines with escaped search pattern

Bash
I am follow the example of using sed to insert lines into a file at a specific pattern-match location. I have run the example from that question on my...
3 years ago

GREP search modification: filter by string

Bash
I have following grep command which looks for 'Exception in' string in the logs for past 24 hours via remote machine and prints out next 40 lines. ss...
3 years ago

Iterating over associative array in bash

Bash
I am renaming strings recursively using an associative array. Th array part is working, when I echo $index & ${code_names[$index]}they print corre...
3 years ago

Writing a Bash script pulling every word that is separated by a comma out of a text file

Bash
I'm trying to write a Bash script that will read a text file and pull out every word that is followed by a comma on a new line. I tried using grep but...
3 years ago

remove blank lines from csv using shell script for oracle

Bash
Hi am using following shell script to create csv from oracle database export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server export P...
3 years ago

How to use OR condition inside tcsh if statement

Bash
I am trying to use OR condition inside an IF statement in tcsh shell. Same statement works fine in CSH but not working on TCSH. I have not much expose...
3 years ago

Bash script for a slideshow with image list refresh

Bash
I'm writing a short script for a slideshow using fbi. For sake of completeness, the script gets executed after an automatic login on an Ubuntu machine...
3 years ago

Can one read input into a element of a associative array?

Bash
I want to use read to put data into a particular element of an associative array, so I wrote the following: typeset -Ag aa aa[key]='initial value' .....
3 years ago

Unix: removing duplicate lines without sorting

Bash
I have a utility script in Python: #!/usr/bin/env python import sys unique_lines = [] duplicate_lines = [] for line in sys.stdin: if line in unique...
3 years ago

character case conversion Uppercase to Lower and vice versa

Bash
I was trying to convert the lowercase characters to uppercase. I came across various alternatives like one listing at the StackOverflow question. Howe...
3 years ago