Skip to content
Advertisement

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’ tempfile.txt The result is: This is my desired output. So as you can

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

Shell script doesn’t work when I export a variable inside it

I have a script called installscript which needs a change to the PATH variable. BuildScript file has the following code: Running ./BuildScript or source BuildScript fails with an error in installscript I have made a NewScript and call BuildScript from it after exporting the PATH variable running source NewScript works. I don’t understand why running BuildScript alone won’t work. Answer

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? Would it be as easy as: Answer

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 aren’t closing the ends of the pipe that get duplicated over

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.e. the lines between “!

Which system calls are not interrupted by a signal?

AFAIK, most of the system calls on linux/unix are interrupted when a signal is received. According to the blog post below, there are some system calls that are not interrupted: In general function that return immediately (don’t wait for any I/O operation to complete or sleep) are not interruptible like socket(2) which just allocates a socket and doesn’t wait for

Bash, tar “cannot stat no such file or directory” [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Closed 7 years ago. 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 Exchange site, you can leave a comment to

Advertisement