General :: Sed Remove All Occurrences In A String?
Nov 21, 2010I have:
Code:
C:u002Cdatau002CDocuments
If I used:
Code:
sed 's/u0052//'
It only removes the first occurrence. How can I remove all occurrence in the line?
I have:
Code:
C:u002Cdatau002CDocuments
If I used:
Code:
sed 's/u0052//'
It only removes the first occurrence. How can I remove all occurrence in the line?
How do I find a string in files in a directory. And these file names begin with letter a. I also want to get the number of occurrences of this string from the grep I run.
I tried this:
cat * | grep -c string but it searches all files. I just want to search files that begin with letter a
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.
View 9 Replies View RelatedSome help with this problem:Code:Write a function that counts the number of occurrences of a pair of letters in a string
View 13 Replies View RelatedI have a data set that takes the form...
0.0 43
12572.9102 80.8521 263.3575 0.0200 12.6358 -86.4942
4.3870e-06 -0.3547
[code]....
I am trying to remove all the files in a directory hierarchy which a certain string inside the file (not the file name, it is the file content).
I can list out all the file name which has a string in the file using 'grep -r -l mystringlooking for'.
But how can I remove all the files returned by the grep ? I am trying this on ubuntu.
I would like to remove a string pattern which like this.You should not remove this /*This is the part should remove*/ You should not remove this.I would like to remove all the text inside the /* and */.
View 2 Replies View RelatedHow can you remove files containing a specific string?I have...Code:find |grep 'string'This may return several results and I wanted to rm the results.I also have...Code:ls -l |grep 'string'|awk '{print $9}'which also may return results.But point is, I can't supply the results as a parameter to rmI was thinking of looping but I don't know how to access the results as if they were an array or something.
View 5 Replies View RelatedI have been fighting with a sed statement trying to get it to remove everything in a string until the last match and have been failing badly. how to get this to work..
sed --> enterprises.9.9.171.1.5.2.1.1.5
returns 5
I want sed to strip everything out until the last period. The final digit can and will change. Some parts before the final period can change as well, since enterprises will sometimes also be represented as more numbers and periods.
need all spaces between two letters or a letter and a number exchanged for an underscore, but all spaces between a letter and other characters need to remain. One example for clarity:
Input:
force -- lamin 90 [label]
active A -- generation [label]
needed Output:
force -- lamin_90 [label]
active_A -- generation [label]
I tried solving this with sed but obviously s/ /_/g does not work, nor does any s/[a-zA-z0-9] [a-zA-z0-9]/[a-zA-z0-9]_[a-zA-z0-9]/g , because you just can't do this...
i try to make a script in bash that u choose a number for example 501 and another number like 1 and find how much the 1 number repeat in all numbers from 1 to 501 for example 11 -->1 repeat 2 times.in 1 to 501 the number 1 repeat 200 times.
View 4 Replies View RelatedAlmost by mistake, I figured out you could do something like:
$ cp foo.data bar1.data
$ ^bar1^bar2
And that runs the same command with bar2.data instead of bar1.data. Now, how about if I have multiple occurrences of the target word? For example:
$ cp foo.data bar.data
$ ^data^index
It only replaces the first data extension. How do I get it to replace both?
I have a string of files named recup_dir.1 thru .66. I have the command sudo rm -r /home/"name"/Pictures/recup_dir.1 to remove them one at a time, how do I remove 20 or thirty at one command?
View 5 Replies View Relatedcopy string a to string b and change string b with toupper() and count the chars
View 3 Replies View RelatedHow can I remove this string from all files. I am not sure how it did get there
PHP Code:
<?php /**/eval(base64_decode('')); ?>
I tried this but It did not work
PHP Code:
find . -iname *.php* -exec sed -i 's/<?php /**/eval(base64_decode('')); ?> //g' {} ;
I have a text file which include code...
I mean, this string should be removed from each line and save in another file.
I am reading strings from a file using readline() function,the file contains some strings which has only special characters, I need to avoid the strings which has only special characters, the special characters are not similar. How to do it in python.??
View 2 Replies View RelatedI want to replace a string of directory path in a string to empty:
Code:
But this doesnt seem to give me the desired thing:
Code:
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.
I am working with a Tcl script and have some strings in the following format (RE):
[a-zA-Z]+[0-9]{6}-[0-9]
There are some leading letters, combinations of capital and lowercase. Then six digits, followed by a hyphen, then one more digit. I would like to remove all of the leading alphabetic characters from the string. The resulting string would then be in this format: [0-9]{6}-[0-9]. In other words, six numeric digits, a hyphen, then one more digit.
I have tried:
Code:
set newstr [string trimleft $origstr alpha]
But that only removes the first alphabetic character, not all of them.
I couldn't get anything with regsub to work correctly, but I am somewhat of a noob with RE's in general and regsub in particular. There are usually 5 leading letters at the beginning of these strings, and I could in most cases get away with using string replace and constant indices to extract the substring. However, my preference is for this to be robust enough to handle all cases with 1 through n leading alphabetic characters.
My server was hit with an injection script which has placed code across many of my clients files. I need a script that can remove a block of php code that spans multiple lines, multiple directories/files and is dynamic, meaning that part of the code changes. I think using find/sed is what I need but cannot seem to figure out how to get it to work.The following is the script that is being injected everywhere. The catch is that they have generated dynamic code at the start/end of the script. (I have commented the parts that are dynamically changing on EVERY instance).PLEASE NOTE: Directly following this script is the start of a valid php script that I do not want to delete.
<?php
//{{65281980 - DYNAMIC!!
GLOBAL $alreadyxxx;
[code]...
In a file,
I need to remove a part of string: /o
string:
or
the string can be
here I need to remove /d2
So, I need to remove everything after when I get last /
i have a file name using the following pattern:
PREFIX: AR
SOURCE: LEGACY
DATETIME: YYYYMMDD_HH24MISS
SUFFIX: .txt
sample filename:AR_LEGACY_20101104_105500.txti want to extract the source which is LEGACY in this case. how do i do this using shell?
I have a large text file that's formatted sort of like this:
Code:
foo bar
blah
[code]...
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
grep <executionID> <auditfile> | awk '{ print $1, $2, $3, $4, substr($5,1,8}
FIX -> Mon 3/1/2010 08:30:04
FIX <- Mon 3/1/2010 08:32:36
FIX <- Mon 3/1/2010 08:35:08
[code].....
anyhow - i append two sed commands to further clarify the direction of the message.
awk '{ print $1, $2, $3, $4, substr($5,1,8} | sed -e 's/->/ ->IN/g' | sed -e 's/<-/<-OUT/g'
FIX -> IN Mon 3/1/2010 08:30:04
FIX <- OUT Mon 3/1/2010 08:32:36
[code]....
I tried using an awk gsub () command within the string instead of the two seds, but it did not work:
awk '{ print gsub(/<regex>/, <replace with>,$1), $2, $3, $4, substr($5,1,8}
the sed works ok, but it would be cooler to make the replacement within the awk command:
gsub(/->/,-> IN, $1)
Is there a way where i could replace the value of the $1 column in the awk print string?
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:
[Code]....
Sempron 3100+, 512mb 400mhz RAM, Ubuntu 10.04 32-bit.From what I've noticed, the computer seems to primarily lock up when an internet browser is open and/or being navigated (I'm testing this observation, now). I've tried Firefox and then installed Chrome; same thing.CTRL+ALT+F1 unresponsive, mouse is frozen.Note that this is an old build given to me by a friend. The build originally had one stick of 512mb and 256mb. I took out the 256 for diagnostic purposes. Additionally, the computer originally had an nVidia 6200 graphics card, which I replaced with a 6600 I had lying around--again for diagnostic purposes. I installed the recommended video drivers respectively. After three re-installations of Ubuntu, 2 different browsers, 2 different graphics cards, running memtest86 and singling out the RAM, and using a can of air to eliminate any overheating issues, I'm unsure what to do next. I have a feeling this is operating system related, though. In BIOS, the CPU fan seems to be running at fine RPMs, but no temperature is given
Do note I am entirely new to the Ubuntu/Linux OS, and wanted a cheap, nice solution for this salvaged PC that I'm giving to my little sister. edit #1: Left the computer idling on desktop with no browser open; seemed okay for hours on end. I opened Chrome to the google homepage (with the Pac-Man flash theme at the time), and it did not freeze then as well when set to idle for hours at a time.
I'm trying to process a postscript file and I want to change alternate pages by finding the string '%%EndPageSetup' (and then adding a line after it).
I've tried using sed with labels and a branching program to ignore the odd occurrences and process the even ones. In the code below I tried searching for the first and ignoring it by jumping to next and processing it and then to the next odd page and so on.
My logic is obviously flawed here as it doesn't work but I've tried the following:
Code:
#!/bin/bash
sed -e '/%%EndPageSetup/{
b even
:odd
/%%EndPageSetup/ b even
:even
s/%%EndPageSetup/%%EndPageSetup++/ b odd}' filename.ps > newfile.ps
In linux, what's a good way to find all occurrences of "string1" in files under a directory and replace them with "string2"?
View 1 Replies View RelatedHere's the actual line of code, which exists in a bash script:
Code:
I want to replace instances like this:
Code:
with this:
Code:
Using this:
Code:
Which works great when there's only ONE of the pattern on the line. But in a case like the "actual line" I posted first, where there are two patterns, separated by a slash, only ONE gets replaced
Watch:
Code:
Why? There must be (among many other things) something I'm not knowing about sed, that's causing this.
-- I'm currently using the ~ (tilde) as the separator in the sed command. It doesn't matter, I've used / ~ and % with no difference.
-- As a test, I tried putting a different character(s) in the middle of the original pattern instead of the / but that made no difference.
-- I've come up with various similar but slightly different regexs that will do this replacement, but they all have had this same result.
-- I tried the sed single-quoted, double-quoted, and unquoted; the latter fails to execute, and the formers both work as described here: wrong.
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.
View 4 Replies View Related