Red Hat / Fedora :: Yank (and Even Cooler Replace) A Line In A Bunch Of Files?
Jun 27, 2011
is there a simple shell script that would recurse all /home/xxx/public_html directories, and then yank this line (it will always be exactly the same) and better yet, for future, is there any way I can REPACE that line with another..
Hello, I need some help searching through multiple files, finding a line and replacing that line. The line I am searching for is:
password key ******* 1222554
ultimately I want to be able to delete the numbers after the asterisks . my thoughts are to create a script that will search for the line password key ******* and delete it then replace it with password key ******* my files are located in /opt and they are all txt files.
I'm pretty sure this is doable from the command line, but my CLI skills have degraded a lot since my pre-Y2K admin days. The goal is to search all the files in the directory for a very long string of text and replace it with another string of text. The text being searched for is my Google Adsense code (which will be stripped from my website) and it will be replaced with a placeholder so I can easily tack something else in there in the future.
Seeing how I have that long snip of code on about 100 pages, automating the process would make life easier. If I was searching for a single word, I can see ways to do this. If I paste the code I'm searching for into a text file, is there a way to: find (contents of oldstring.txt) and replace with (contents of newstring.txt)?
But the variable $sentence can not be identified in ' ' . And also you can see I just want to update the old file. But the sed command can not save the file for me ,so I need to write them to a new file and over write the new file .
At the moment I have a flat file which is being used by a few people. I want a script to remotely change the file, so I can start logging who is doing what.At this point here is one requirement I am trying to develop. We have text blocks who pretty much look like.I hope this is somewhat clear. I try to find $param for the right $workflow and change that. Can you help me to find $$var3 and change that?
Oftentimes, I want to restore a directory from a tar.gz backup file.When I extract the backup tar.gz, is there a way to make it only replace newer files in t directory?Currently, I have only been able to achieve this bydeleting the entire target directory and extracting the entire backup file. This is timeonsuming because the backups are sometimes hundreds of gigabytes.
I have been playing with JWM source and found this cool tutorial at Debian Forums about how its easier to generate a .deb vs installing from source in the traditional manner (./configure, make,etc)[URL] My problem is that when doing the command
dpkg-buildpackage -rfakeroot -us -uc
it starts over, destroys the previous jwm stuff, including my custom files and generates a .deb so, how do I stop it from "cleaning" when i run the above command?
I keep a backup of a bunch of files on a flash drive, so that whenever I change distributions I can just restore all my Android stuff (saves on re-downloading everything). One of these is the Android SDK.
In my ~/.bashrc I add the paths to some executables in the SDK, only if the directory exists, and only if the path is not already in $PATH. For the Android NDK this works fine, but for the SDK I get this:
Code: snfo@snfo:~$ adb devices bash: /home/snfo/Android/sdk/platform-tools/adb: No such file or directory snfo@snfo:~$ ls -F /home/snfo/Android/sdk/platform-tools/adb /home/snfo/Android/sdk/platform-tools/adb*
Everything else is fine though, just that one path is causing trouble.
Now, I've saw something similar to this before whenever you move an executable from one place to another. If you don't re-source your bash config it will continue to keep looking wherever it used to be located. But I've never moved these files.
Basically I need to rename a bunch of .doc files using the for-structure and the mv command (w/ wildcards) in bash. I guess this would be a bit easier if I'd use the rename command, but since this is a school assignment of sorts I need to use for & mv. The .doc files are named "1filename.doc", "2filename.doc" etc. And I've got to rename them to "aaa_1filename.doc", "aaa_2filename.doc", "aaa_3filename.doc" and so on. Tried to dabble quite a bit with the for and mv commands, basically just got a bunch of errors. Every damn time. For 2 hours. The most common error was "mv: missing destination file operand after ..."
I'm not asking for help here, just documenting something I just discovered. Yesterday I wanted to batch-convert a bunch of old wma files to ogg vorbis. Not wanting to go through intermediate wav files, I tried to use ffmpeg to do it in one go. I first tried using the following command (in a loop, which I won't print here).
Code: ffmpeg -i $file -f ogg -acodec vorbis -ab 192k outputdir/$file "vorbis" turns out to be the built-in libavc implementation of the codec. In the process I discovered that the -ab value is always ignored. No matter what value you put, the output is always the default 64k (average, but of course it's vbr). You can however use the poorly-documented -aq option to set the audio quality used. The values don't correspond to the oggenc values though, being a number ranging from 10-100 (or more, I don't know what the maximum is). It's not exactly clear what number corresponds to what average bitrate, so you have to experiment. ~30 seems to give you an average-rate file, while anything above 60 is probably overkill.
Switching to the external libvorbis gave me more flexibility, although at a cost of much longer encoding times (note that ffmpeg must have been compiled with libvorbis support first).
I could use both -ab and -aq (with the numbers corresponding to the oggenc values), with no problems. ffmpeg does display some wrong values in it's output text, however. In addition, there's one more difference. The vorbis (libavc) codec provides an entry in the header of the ogg container reporting the average bitrate, but it doesn't appear to provide a similar bitrate header in the vorbis stream itself. Some programs may not report the bitrate value because of this.
libvorbis provides both headers, avoiding that problem. So to summarize, libvorbis appears to be a better codec choice than vorbis.
I have an rsnapshot backup that I need to move off of a corrupt Linux file system. I need to preserve the internal hardlinks. I've tried rsync -H and using a newer rsync and neither preserve the hardlinks on OS X.
I tried to get rsync -H working and I've isolated it to the file system mounted. I can preserve hard links copying locally (HFS to HFS) but it doesn't preserve when I try to rsync off of a SMB file system mount or AFP file system mount. Is there some mount option solution to getting OS X rsync to obey -H?
I keep trying to convert a bunch of jpg files into pdf, but ImageMagick just seems to keep failing there. Well well, after three thousand fix and reinstall attempts (seriously, I've been trying to fix it for the last month or so), this is what I'm getting today:
I trying to change a file with hundreds of entries, replacing line with "IP Address Number" for "Host Name", one for another.
this is the original: [IP Address Configuration : "172_17_27_161.SUBNET_U"] IP Address Number = 172.17.27.161Assignment Type = 8Host Name = CAST124Last Used = 1290499294000MAC Address = 1 00 16 35 74 4C 59Client Identifier = 01 00 16 35 74 4C 59and the result desired is: [IP Address Configuration : "172_17_27_161.SUBNET_U"]Host Name = CAST124Assignment Type = 8IP Address Number = 172.17.27.161Last Used = 1290499294000MAC Address = 1 00 16 35 74 4C 59Client Identifier = 01 00 16 35 74 4C 59I know how to change one character by another with sed, but not to change a line for another, because I don't know in which line number it is.
15 for(i = 0; i < N; i++) I want to replace "i" with "test" in the line above,whose line number is 15. When I tried this command :15s/i/test/ Line 15 turned to be this: for(test = 0; i < N; i++) It only replace the first "i",but I want to change all "i" in line 15.
I am trying to write a program in C which compares two files and prints the line that is equal.
Here file1.txt has
and file2.txt has
Note: file2.txt consist of only a single string where as file2.txt has multiple lines. Actually im comparing two files with md5sum values.
Here is the code but it compares only first line of files..but it should compare the whole file1..and sorry iam a beginner in C can any1 sujest some modification to this code so that..it can compare file2 with entire file1
I have a line of text with multiple web links in the line. I'd like to replace the actual links with the text "<web-link>" so I don't accidentally hit them while reading on my iphone. I've tried many versions of the following sed command, sed 's/(http.*)/<web_link>/g', but it simply replaces everything between the first instance of "(http" and the last instance of ")" with <web_link>, or does nothing at all.
Ex: This line has a link to a web page (http://www.webpage.com/file.html) then some more text (extra text) and then another link (http://www.nextwebpage.com.index.html) to a website. $ echo "This line has a link to a web page (http://www.webpage.com/file.html) then some more text (extra text) and then another link (http://www.nextwebpage.com.index.html) to a website." | sed 's/(http.*)/<web_link>/g'
What I get is: This line has a link to a web page <web_link> to a website. What I'd like is: This line has a link to a web page <web_link> then some more text (extra text) and then another link <web_link> to a website. What am I doing wrong with my sed command?
I need to replace a line in the lvm.conf file from: filter = [ "r|/dev/.*/by-path/.*|", "r|/dev/.*/by-id/.*|", "a/.*/" ] to: filter = [ "a|/dev/cciss/c0d0.*|", "a|/dev/disk/by-id/.*|", "r|.*|" ] And I was hoping there was a way to use sed or awk to do this in a script (as I need to repeat this on several machines).
All of the examples I've found don't see to work with all of the special characters in the line that I need to replace. Then I need to add a line after the above edit like this: types = [ "device-mapper", 253 ]
I have a laptop cooler that sits under my laptop and has 4 USB ports on the back. It plugs into my laptop via USB and that is the only source of power it has. The issue is when I try to boot Ubuntu with it plugged in it hangs forever and if I unplug it then it seems to boot up just fine. This happens even if nothing is plugged into the ports on the cooler. I also notice that if I plug the cooler in after Ubuntu is fully booted it will work but does not see things plugged into it every time.
I have a jar, and I need to replace a class in it, at this moment, I can only open it with "archive manager" and then drag and drop the new compiled class into the jar, but I think this is really boring, if I can do with with just a command ?
I'm trying to use sed to search for a certain 'primary' pattern that may exist on several lines, with each primary pattern followed by an --unknown-- number of 'secondary' patterns.The lines containing the pattern start with: test(header_name)On that same line is an arbitrary number of strings that come after it.I want to move those strings over to their own lines so that they each are preceded by their own test(header_name).e.g. Original file (mytest.txt):
apples test("Type1", "hat", "cat", "dog", "house"); bananas
I need a command to search a string in a file and then to convert the next string in the same line from hexadecimal to binary. I was able to put everything in capitals. The original file can be as such:
E 2 C 1 794 T ffff E 2 C 1 787
It is not always FFFF! I am trying to do this in a file at once, not reading line by line (using while).
I would like to have a script that will do a search in an XML file for a specific block of XML code and replace it with a different block of XML code using the Windows build of GNU Sed 4.1.5.
Here's the text I want to find:
And here's what I want to replace it with:
There is however a lot of stuff in there that would mess up sed, and the one example from the sed FAQ (from the Sourceforge site) that looked promising and easy enough to figure out (4.23.3. Try to use a block of "literal strings") fails with this error message: sed: file blockrep.sed line 18: unterminated `s' command
Anyone got any ideas, or even an alternate program that can do this? (Preferably one that I can automate.)