I want to replace a line with double quotes on OpenBox startup, like: with I use this command, but it does not work: It gives me this error: Answer The ampersand in the replacement string recalls the pattern in the search string. So you can just do this: Also, you can use single quotes on the outside, and dou…
Tag: unix
Using the setuid bit in Linux
I have this C file: I compile it, set the UID and GID both to root and set the setuid bit, so that it looks like this: However when I call $ ./a.out I still get: What am I doing wrong? Answer The real user ID is still the user that called the program, but the effective user ID is
Print error for missing argument
I am trying to write a script which will check number of arguments for first and second number; if both variable entered, it will do the calculation; if one argument is missing, it will print error message. Here what I’ve done so far: I am always getting error message even though I enter both of the num…
Save all data into variable tcl
I have a code which i want to use to open a log file, extract the contents and save it into a variable so i can extract the data from the variable in the future. How do i do that? So far the code saves only the last data of the log file into the variable. I think the while
tail the last modified file and monitor for new files in bash
I can tail -f the last modified file using ls –sort=time | head -1 | xargs tail -f but I’m looking for something that would continuously run the first part as well, i.e. if a new files is created while the tail command is running it switches to tailing the new file. I thought about using watch com…
script for deleting queues using a certain prefix
i have a file named “Output_File.txt” containing a list of local queues and i want to write a script to delete those queues. what i wrote is: the problem is that the script does delete the queues but prints for every deleted queue the following output: how can i alter the code to delete the queues…
Recursively grep unique pattern in different files
Sorry title is not very clear. So let’s say I’m grepping recursively for urls like this: grep -ERo ‘(http|https)://[^/”]+’ /folder and in folder there are several files containing the same url. My goal is to output only once this url. I tried to pipe the grep to | uniq or sort -u…
mkdir makes wrong directory names when used with cut on *.tex files
When make directories for each file with certain extension: …everything works just fine. However if I do it for .tex files I get following results: I just wanted to clean my latex directory and I get weird directory names. Why is that and how to make it work? Answer It is error prone to use output from …
Executable Unix script cannot be found by which command
I have a Unix bash script written by a former teammate that must be in my PATH, though I can’t find it by manual inspection (see below). I can however execute it anywhere by just typing I would like to view and edit this script. However, when I try to find it via the which command, I get a blank
How can I control the number of running processes?
I’m doing a shell script and the unknown situation occurred. I must execute a certain number of processes, lets suppose 12. But I want to limit the executions by ‘t’ each time. So if ‘t’ is 3 I would have to execute 3 processes then 3, 3 and finally 3. But I would like to do it a…