General :: Sed Command Does Not Perform Substitution
Jul 22, 2010
I've been trying to use a find command with -exec to find the differences between identically-named files in different paths. My initial attempt was to do something like this:
Code: find trunk/ -type f -not -path '*.svn*' -exec diff '{}' `echo '{}' | sed 's/^trunk///'` ;
Unfortunately this does not work at all as expected (the diff ends up executing on the same file)! I have narrowed it down to the subshell (inside the ``) but beyond that I have no idea. For some reason the sed, though written correctly, does not perform the substitution. I've changed the diff to echo and played with the sed command and the only way I can get it to perform _any_ substitution is to use .* as the regex. Even s/.*trunk.*/SUB/ doesn't work. Any insight into the inner workings of -exec/subshells/pipes or some crap I'm missing? Don't worry about rewriting the command to make it work; I simply swapped the paths and got rid of the subshell nonsense and everything works fine.
I was to set up a cronjob that sends its output to a logfile, i want that log file to be unique. the easiest way to set this up would be to make the directory in the script, then output the command to that directory, they call that directory via is full path in cron (because cron only uses full path names.
This does not work
keep in mind the command "/bin/mkdir -p /tmp/pw_log/`date +20%y%m%d_%H%M%S`.log" works fine on the command line - but once I put it in the shell, it does not work.
The first call to "somefunction" works as expected. The function prints "endfunction" and a process in background sleeps 30 seconds. In the second call I thought it should work in the same way, but the script sleeps 30 seconds before it prints "endfunction".Does someone know the reason of this behavior? Is there another way to do a command substitution of a function that has a background process without have to waiting for that process?
if{ [catch {sqlite3 db /path/to/db/file} result] } { puts stderr $result } else { do something }
What I want is to use a variable for the file name/path. When I put in a variable instead of the absolute path, I get an error: "missing close-brace: possible unbalanced brace in comment while executing"
This is weird because when I run the code with the fully qualified pathname, it works fine. I substitute out the pathname for a variable containing the pathname ($variable) and I get this error.
I need to perform ls, cp & tar in a directory that contains 80k text files, but i understand that there are limitation for files 70000 files and above.
I would like to know how can i perform such command e.g "ls -l | wc -l" with so many files.
Is there an equivalent command that will perform the same task as ALT+F4 keystroke? I want to create a simple script that lirc can use so I can set up a button on my remote to close program windows that pop up (like when plugging in usb thumb drives, inserting a dvd, and other windows), and avoid having to remote desktop or go into CLI to kill the window.
I read up on sed and I am confused about it and regular expressions. I am trying to replace some text on one line in a file with some text.
original text: $normal['']; replaced with: $normal['localhost'];
In my script file file I've tried numerous combinations of delimiters, etc but obviously don't understand all the rules of regular expressions. My current sed command was:
sed -i 's/$normal[''];/$normal['localhost'];/g' /path_to_file I also saw some examples using variables, so I tried that: bb1="$normal[''];" bb2="$normal['localhost'];" echo $bb1 echo $bb2 sed -i 's/"$bb1"/"$bb2"/g' /path_to_file
In the above test, the echos both show the correct text but nothing happens to the real file.
So, I have 100 folders each of them include a file called script.txt and script2.txt. the file script.txt has and 100include files that have the same name like the folders. So, for example if I have the folders A, B and C then the script.txt will include 3lines such as:
*include A *include B *include C
I want for each folder (A, B and C) to create script2.txt which will substitute *include A with $include A, respectively for each folder.
so for folder A, I will have script2.txt
$include A *include B *include C
[Code].....
but it is substituting "*" with "$" in each file for all the lines. I think i should probably close earlier a loop.
I'm writing a C++ application and need to work with process substitution in the Bash shell. I'm trying to find a way to validate the paths passed as arguments to my program, some of which point to FIFO files created by process substitution.
Is there a shell (or C++) way that I can check if the system creates these files in /dev/fd or if they are created somewhere else?
is there an easy way for me to get the hardware specs of a linux machine, such as number and type of processors, RAM, BIOS version, # of power supplies, etc from a command line?
I'm dealing with Dell servers, but even if i can just get number and type of processors and RAM config, that'd be great. I know how to easily do it in Windows, no clue on Linux.
Currently I backing up the MBR, the C and the other partitions to an external USB HDD and from there I restore them if needed. I use the SystemRescueCd and commands like dd if=/dev/sd* of=/mnt/PC_name/backupmbr.1 count=1 bs=512 and ntfsclone --save-image --output /mnt/PC_name/PC_name_c.img /dev/sd*1 etc. I want to clone the HDD the way, however, that I omit the external USB drive. I want to connect the new HDD to the PC and do the cloning directly from one disc to the other.
My questions are:
- Can you provide me with the exact command? - Is that a difference if the disc is SATA or IDE? - Can I copy the disc even if the old disc don't wan to boot?
I need to perform patching on some RHEL boxes. This the first time i am gonna do this. Kindly advise, how and what are the steps i should take to perform the OS patching.
Can one perform an installation of CentOS 5 (5.4) so that the system is up-to-date at the time of the first boot (i.e. Anaconda will pull and install the 'latest' versions of the packages directly, and the user needn't run `yum update` | `yum upgrade` after the system has been installed)?
If this is doable at all, is it possible to accomplish without making use of a personally custom-crafted-and-hosted repository (i.e. can one of the official CentOS mirrors be used)?
Also, I'm not talking about creating an install DVD containing the latest versions of the packages, but rather, if the netinstall media can be used to perform this particular type of installation.
I am using debian 5.04 + LXDE. In the past, I sometime encounter problems such as the distro broken after performed a full apt dist-upgrade or upgrade. Now, I am more conservative, I am using apt safe-upgrade.
I want to know are there anyway to do a better safe upgrade for debian without breaking the distro?
I want to perform an e2fsck with the y switch (so I dont have to answer yes to every question) on two volumes on a server the next time I restart it. I don't want to do a shutdown -rF because 1) I dont want to check the other volumes and 2) it seems when I do that, the e2fsck doesn't keep restarting itself over and over to fix all the problems. Seems like it runs once, then if it fails it drops you to the repair console in single user mode. I'd rather just have it start the check that will keep repeating over and over right away, because I know it'll take more than one pass.
The odd-numbered lines containing >SEQUENCE# are the headers and the even-numbered lines containing a variety of characters represent DNA sequence read quality scores.
I want to replace all of the greater-than (">") symbols in the quality scores (even-numbered lines) with a "0" but I want to leave the greater-than symbols on the odd-numbered lines alone. I would just use sed -i '/^>/! s/>/0/g' $FileName but sometimes the quality scores begin with a ">" as well.
I'm sure there is a simple modification of a normal sed command with an "n" inserted somewhere but I can't figure it out.
Anyone know how to remotely boot a server so that a network boot (F12) automatically starts? For example, in Solaris, I can type "reboot -- net -s" (hope i remembered the syntax - been a while! )to reboot my server and begin a network installation without having to be at the console. I am looking for the same in SLES.
I am arthritic and I have considerable difficulty with a double click. I also have difficulty when using a mouse of moving the mouse as I select something (click the button) from whatever window I am working with and thereby selecting the wrong thing. To compensate for this difficulty, I use a Logitech trackball and program the center button to perform a double click with one stroke. I am currently struggling with Linux Mint 9 in my search for a Windows alternative. Is there any way to program my center button (scroll wheel) to perform a double click in this or any other Linux version? Alternatively, is there any way to program a keyboard key to perform a double mouse click with a single stroke? I do not want any multiple key combinations for this operation, I want something that works with a single click of one button.
answer this question?How to create a cron file that will regularly perform the following backups:a. Performs a level 0 backup once per monthb.Performs a level 2 dump one day per weekc.Performs a level 5 dump every day that neither a level 0 nor a level 2 dump is performed. If not, I'm I close? This is homework, so I don't want a direct answer
I have a folder named "logs" which contains log files. I would like to have a bash script or a cron job or something like this which will check the folder continuousy and perform some tasks (for example echo "New file is created") every time a new file with pattern like "Screen.log.***" is created in the folder "logs" Is it possible in Linux?
My root partition is formatted as ext3 and I would like to perform a bad blocks scan on it. Normally e2fsck -c -c does this, but you can not run it on a mounted partition. I know it is possible to force a fsck to run at boot by creating the file /forcefsck but is it possible to specify that it should also check for bad blocks? If not, what is the recommended way to check for bad blocks on the root partition? I would like to avoid having to create a rescue disk and boot off of it.
I use the Actions feature of KDE's Klipper utility to run certain commands when I copy something into the clipboard that matches a particular regular expression. Unfortunately, I have to turn on Enable Clipboard Actions and select the command from a menu every time I copy something that I want to run the command on. I'd like to have that command run automatically instead.
You'd think this was possible, as there is an automatic checkbox in the action settings dialog box:
Unfortunately, that appears to do nothing. The documentation included with Klipper does not indicate what that checkbox is supposed to do.
Is it possible to configure Klipper to run a command automatically if the contents of the clipboard matches a regular expression? If not, is there another way to accomplish this?
I need to use Live Media to make changes to a hard disk drive. I tried to sudo to no effect.
Seems like it would be troublesome to authorize root access on Live Media or have sudo allow commands such as pvcreate,lvcreate,vgcreate, especially if the hard disk is not encrypted.
I have to send CVs to people as Word docs. I compose them using Linux Libertine font. This means that if I send them as they are, they will almost certainly be viewed in a completely inappropriate font. I have tried creating a copy converted to Times New Roman, but the result is inferior. I am also uncomfortable with this because I tend to end up with the originals the copies out of sync. I would rather have just one doc file for each type of CV.What I would like to know is:
1. Is there a serif font that all MS Office users are certain to have that is a less scrappy looking alternative to Times New Roman? It doesn't have to look identical to Linux Libertine, but none of the other MS core fonts look right. 2. Is there a way of specifying a generic serif font as a substitution in Word docs created in OpenOffice Writer like there is in HTML?