Skip to content

Tag: unix

Match two lines, replace with three lines

I need to use sed to replace every matching two-line pattern with a three line pattern. Here’s my input file (tempfile.txt). Basically, if a client-hostname “HOSTNAME”; is missing, then it should be replaced with a tab and then a newline. My attempt: sed ‘N; /hardware.*}/d; P; D’…

Delete a single line from a file with a unix shell script

I’m working with a simple shell script that needs to delete a single line from a file if a string entered at command line is found. Instead it deletes the entire contents of the file. the data file is like this(each entry is on a new line): my code: Answer N means the line number , begin from 1

Running shell script using .env file

I am fairly new to running scripts in UNIX/Linux. I have a .env file containing environment information and a .sh script containing folder creations etc for that environment. How would I run the script on the environment contained in the .env file or how could I point the script to the target environment? Wou…

Unix pipe experiment hangs

The problem is that this program won’t output the expected START and END, also not exiting unless I kill it from shell. Answer You have the order of the dup2( existing_fd, new_fd ) parameters reversed. You have another bug that breaks lots of “let’s try out pipe(2)” experiments. You ar…

Grep lines from a file in batches according to a format

I have a file with contents as: Hi welcome ! Chunk Start Line 1Line2! Chunk Start Line 1 Line 2 Line 3 ! Chunk Start Line 1Line 2Line 3Line 1Line 2Line 3Line 4Line 5Line 1Line 2Line 3Line 4 Now, everything beginning with “! Chunk Start” and before the next “! Chunk Start” is a chunk, i…