Ubuntu :: Bash Script To Delete/replace A Specific String Of Text?
Jun 17, 2010
What i want to do is pretty simple.I want to uncomment every line that begins with "deb" (except for deb cdrom) in /etc/apt/sources.list.I know how to do this through system > administration > software sources.I know I can gksu gedit /etc/apt/sources.list.I'd rather not do it that way.I'd rather have a script do it. It's less work, less typing, less clicking, and would work the same on every ubuntu version.
These must a be a question you received a lot, but I couldn't find a similar thread! It's a simple question. I need to delete a specific string from a file. For example the specific numbers "3456" from a file. I've tried with the tr comand, using Code: tr -d '3456' file, but it also deleted whichever ocurrence of 3,4,5,6 from my file. Should I use a regular expression?
I have large text files with space delimited strings (2-5). The strings can contain "'" or "-". I'd like to replace say the second space with a pipe. What's the best way to go? Using sed I was thinking of this:
I want to use SED to do the following: In a text file replace any occurrences of the three character string ZZZ with a quotation mark "and. replace all occurrences of a comma with a semi-colon. It is the S/ / / command which is stumping me on the first issue...inparticular how to get the replace string to be quote.
I am a member of a group which has written a program whose source code is being held in a specific directory (~cs252/Assignments/basicAsst/project) and we want to go through and change the parameters for the function "sequentialInsert." My job is to find all occurances of the function call to "sequentialInsert" and to also list the files from where the code came from. Also, I have to be in the commandsAsst directory when I do this. I have tried grep and find combined together, and I am at a lost.
I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.
perl -pi -e "s/$findstring/$replacestring/" testfile where as $findstring = print F_WC_TMP"$line "; and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line ";
But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.
I'm having problems with Tomboy. I have a few hundred note files and I need to go through all of them and replace all instances of "<link:broken>a</link:broken>" with "a". Is there a bash command I can use to do this?
write such script (bash script). I have some text file with name filename.txt I must check if this file contains string "test-string-first", I must cut from this file string which follows string "keyword-string:" and till first white-space and save it to some variable.
For example. File: PHP Code: PHP Code: Start 15022011 Eng 12-3-42 SN1232324422 11 test-string-first SN322211 securities HH keyword-string:123456321-net mark (11-22)
I have a text file which stores the list of files & dir, I want to get only file's extensions from this file & want to store it in another file.eg, below is the file's contents & from it I want to get the extensions sh, pl & h & want to store it in another file. Also I don't want directory list.
A scripts/services_restarter.sh A scripts/svn post_commit scripts A scripts/tmp/
I want to be able to check the contents of a text file for a specific string and remove it from the file from the command prompt. I would basically be searching through a number of files and if a specific string is found I would like it removed automatically. pretty much a find and replace, were the replace is nothing. any one got any ideas on how you would do this. I already have the search part sorted just need to be able to remove the string I don't want from the multiple files.
I want to replace a string of directory path in a string to empty:
But this doesnt seem to give me the desired thing:
This gives the desired outcome, but its specific, i need a variable in the sed not a string. And if I replace STRING="/mnt/sda1/record/$dd/" then I cant use it for something else, cause its has all the weird backslashes now.
How can I just take the type of the file at the end? I know I can use strrchr() for a period to get the pointer to the period just before file type. Is there a build in string function that will just take the rest of the string from a certain point on forward in the string? I know it wouldn't be much work to make it myself, but I figured I would find out if it already existed before doing it.
i use this script to get the time and date of back and fourth transactions for a particular execution id. I use a substr command on the 5th column to to cut the milli seconds off the time value. - otherwise the times would look like 08:30:04.235
Moving right along, I have a folder of MP3 files containing various Movie sound tracks and scores. I'm using Audio Tag Tool to tag all the files at once with an "Artist" of "Soundtrack", and to inherit the "Title" tag from the file name. After that, I will rename all the files (Using Audio Tag Tool -- awesome program, btw) with the format "<Artist> - <Title>.mp3"
The problem, is many of my files already contain the string "Soundtrack", which would be redundant. I happen to be a perfectionist, so I'm unable to ignore it and move on. Hence my question to you fine folk: I want to delete all instances of "soundtrack" (-i case irrelevant) in the filenames before I go through the above steps. But, its not quite that simple. This is a sample of some of the file names:
I'd like a sed command to replace all decimal values greater than 0.5 with nothing in a tab delimited text file.
There would be one tab before 0.301 and two tabs after it. This way when you paste the text into an excel spreadsheet, there are empty cells where you deleted values.
I thought the sed command would be something like:
But this will delete everything.
What I need is something that will start deleting when it sees 0.[5-9] and stop when it reaches a tab. I know you can use [^character]+ to do this, but it doesn't seem to work with a TAB as the character.
Another idea I had would be to have sed replace from 0.[5-9] to 0. and replace with a tab + 0. But I also cant get [^0.]+ to work as it only works with single characters.
I have to delete a certain line of text from the a textfile via ubuntu's shell scripting.I have done research, and it seems that most people advocate the usage of sed /d option. sed makes does not edit the text file. Hence, most options I discovered involved the use of a temporary variable/textfile and then overwriting the old file with the temporary new file. Is there anyway whereby I can bypass the use of temporary storage containers? I hope there is any magical combination of commands to edit the file directly.
I am trying to replace the first number in a string at the end of the line with the word that matches that number. for example i want to replace 546215 to be five-46215. The command that I have tried is