General :: Grep Or Sed To Delete Matching Pattern?

Jul 7, 2011

How can I use grep -Ev "pattern" not only to delete the matching "pattern" but to edit and save the file permanently as well

View 2 Replies


ADVERTISEMENT

Programming :: Sed: Delete Last Line Matching A Pattern?

Mar 27, 2011

I have a question about sed programming, actually a one-liner for which I cannot find a solution, right now. I need to delete a line matching a specific pattern only if it is the last line. In practice, I would put together the following:

Code:
#
# This deletes the last line of a file

[code]...

View 5 Replies View Related

General :: Listing Files Using Pattern Matching

Mar 13, 2011

I have a requirement to list files using find command My folder contains below list of files with out extention.I have a requirement to exclude only ABC.123.* type files and list others. Even though files having MNO contains this pattern i should not exclude. Even if file ends with .txt or .doc it should not be excluded. That is ABC.123.1234.txt should not be excluded.But I am not getting what is required. Can any one please let me know if I am doing wrong any where. As per my requirement I cannot use grep, -regex, or -regex attributes to find command.

View 7 Replies View Related

General :: Copy All Files Matching Pattern From SRC To DST

Jul 19, 2011

If I wanted to copy all *.so files from src to dst I'd do:
cp src/*.so dst
However, I want to copy all *.so files from src and it's subdirs into dst.

View 2 Replies View Related

General :: File Matching Pattern On Command Line?

Sep 9, 2011

I've got files in a directory as follows:

1.png
1_thumb.png
1-1.png
1-1_thumb.png

[code]....

I want to list all the files that don't have a copy with the same filename with -1 somewhere in it. So, in the example above, the results would be 3.png.

NB: the file and its copy with "-1" in it will be the same filesize, if that helps.

View 2 Replies View Related

General :: Grep Pattern Of Root Directory?

Mar 5, 2011

Want to grep pattern of root dir. (/). Staying in current directory. But I don't want to use the below code:
cd /
grep m *

View 3 Replies View Related

General :: Using Grep With Pattern File And PCRE

Sep 25, 2010

I would like to write a newline delimeted rules file using PCREs for use with the grep command. Grep has the option -f to obtain the search pattern from a file, and option -P to search using PCREs. However, these two options do not work together. The -f option only seems to work with fixed string rules.A friend previously helped me get around this limitation somehow, but I can't remember how he did it. I also would like the ability to add comments at the end of each rule in the file.

View 11 Replies View Related

General :: How To Make Grep To Search A Pattern In Only Specific File Type?

Mar 6, 2010

To search a string pattern in all files in a directory and subdirectories, I am using;

Code:
grep -R "myclass::my-func(" mydirectory/
Now I want grep, to search in only specific file types say *.cc. Please help me. I have read manual of grep, but could not deduce any hint.
Best Regards.

View 7 Replies View Related

Programming :: Add Texts Using Sed In Matching Pattern?

Feb 3, 2011

I need to add some text using sed before and after the matching pattern. Does any one have any clue?e.g.cat /my/file | sed -e "s/first pattern/New Pattern/g" . /my/file.bakNow I need a result like New Pattern

View 7 Replies View Related

Programming :: Make X Number Of Changes Matching Pattern With Sed?

Aug 7, 2010

i tried searching on google but found it difficult to say exactly what I was looking for.Task - Capitalise x number of letters at the start of words.eg. Original line - one.two.three.fourRevised line - One.Two.three.four (here only requiring 2 changes)Test data:

Code:
wire.in.the.blood.s04e01.ws.pdtv.xvid-river.avi
wire.in.the.blood.s04e02.ws.pdtv.xvid-river.avi

[code]...

View 7 Replies View Related

General :: Parse A File And Print Each Line That Ends With Matching Pattern (if The Next Line Is Blank)

Aug 2, 2010

I've written a script to parse a file and print each line that ends with matching pattern, if the next line is blank. The pattern lines are the result of md5sum $i|sed 's/path///g' so that only md5 and filename appear. Here's what I'm using.

Quote:
for fline in `sed -n '/.*.ext$/p' file1`
do
if [ "`sed -n -e '/'"$fline"'/ {n; p;}' file1`" == "" ]
then
echo ""$fline" has no info" >>file2
fi
done
[Code]....

View 4 Replies View Related

Ubuntu :: Text Manipulation - Regex - Pattern Matching?

Jul 12, 2010

Are there some good tutorials or reference materials on how do pattern matching and text manipulation in Linux?I have a few simple tasks I'd like taken care of...like formatting numbers in file names, stripping some text from directory names, etc

View 2 Replies View Related

General :: Delete Matching Files In All Subdirectories?

Feb 22, 2010

How can I remove all .swp files in all of my subdirectories under Linux?

View 4 Replies View Related

Programming :: Multiple Line Pattern Matching And Variable Extraction?

Oct 19, 2010

I have this complex log file filled with entries like

test1-G1/0/0-100-QOS-7001923-ROUTING (ClassMap)
Action: Resolved New
sysName: test1.local

[code]...

View 1 Replies View Related

General :: Use Sed To Delete All Lines Before First Match Of A Pattern?

Apr 14, 2010

I have to use sed with this problem, and sed is extremely complicated, they could probably teach a whole class on this entire function.

Here's an example to show what I need to do:

Code...

how would I say that every line before I reach the first match of "sweet" should be deleted so that the output will look like: Code...

View 9 Replies View Related

Programming :: Inverse Regexp Matching / Developing Of An Idea 'pattern Based Filtration'?

Sep 3, 2010

I am interested in the following problem: given a string (pattern) find a regexp which match this pattern.
I will need this for a developing of an idea 'pattern based filtration'.

View 3 Replies View Related

Software :: Grep And Path Name Matching.?

Jul 16, 2010

Linux kernel 2.6, Slackware 12.0.

I do grep -r string_1 .*txt. Is the path first expanded by the shell? If not, then say, ./elem1/elem2/file1.txt would search for string_1. However, it will not in my system. Note: '.' (period) in .*txt is any char. '.' in ./elem1/elem2/file1.txt is current dir. Now, .*txt should be, as a regexp, zero or more occurrences of any char followed by txt, that is, any string with txt as a suffix.

View 3 Replies View Related

General :: Find/grep/wc Command To Find Matching Files - Print Filename And Word Count?

Sep 11, 2009

I am trying to do a find/grep/wc command to find matching files, print the filename and then the word count of a specific pattern per file. Here is my best (non-working) attempt so far:

wc `find . ( -name "*.as" -o -name "*.mxml" ) -exec grep -H HeightResizableList {}` ;

View 10 Replies View Related

General :: Delete/grab A Line Which Matchs A Pattern Of A Particular Column Only?

Jan 18, 2010

I have found many information about how to delete/grab a line in a text file including delete line with match a pattern but I did not find info about how to delete a line which match a pattern of a particular column only.

for example mydata.txt:
id type x y z
1 6 0.474611 0.227223 0.583947

[code]....

View 6 Replies View Related

General :: Shell Script To Delete File If A Pattern Is Found And Restart Servers?

Jul 22, 2010

I have requirement to delete some log files from a directory if a string"deletethisfile" is found.Then restart the application servers.1. Search for the string ?deletethisfile? in server.log file under a directory, If found 2. Stop that particular server.3. Delete the log file 4. Restart the server.

View 2 Replies View Related

Programming :: How To Grep Pattern Which Is Split In 2 Lines?

Dec 9, 2010

I need to grep a pattern which can be present in one line or could be split in 2 lines.Normal grep wont work in this case. Can anyone please help on this?There are 100's of files in which i need to search for this pattern so time is also a constrain.

View 5 Replies View Related

Programming :: Grep Until Certain Character Or Pattern Appears

Jun 25, 2010

I have the following command that greps "/etc/cron.allow" and displays the following 9 lines of $file grep -A 9 "/etc/cron.allow" $file On the other hand I would like to grep a file for a certain text display the next couple of lines and stop when i hit a specified word or blank or pattern.Basically I would like my grep to end when the shell hits a blank, certain key word or pattern specified in command.

View 7 Replies View Related

Programming :: Searching Pattern In Tab Delimited File Using Grep

Mar 4, 2010

Suppose i have a file(1.txt) separated by TAB delimiter in a line

1 B AB 2
2 C AB 2

if I need to search for the records having B?? using grep.If i need to perform multiple search like line having "C and AB" or "B and AB"??

View 5 Replies View Related

Programming :: Storing Grep Output To Feed Awk To Retrieve Entire Records Matching Variable

Jul 28, 2010

I have two files :

FileA
prot1
prot5
prot9
prot15

[Code]....

What I need to do is to extract from fileB the fields containing only the strings in fileA.

I thought awk could do the job easily with :

Code:
awk 'BEGIN { RS = "###" } /'$variable'/' fileB > output

where variable would maybe be the output of grep from fileA. So can I store the output of grep in a variable to use it afterwards with awk ?

something like that:

Code:
result=`grep prot. fileA` ; awk 'BEGIN { RS = "###" } /'$result'/' fileB > output
but that doesn't work. I'm always getting the entire fileB.

The output of grep get stored in the variable, I verified that with echo. So there is something that I just don't get... It seems to me that the above line should work.

View 11 Replies View Related

Ubuntu :: Bash - Delete First File Matching Regex?

Mar 27, 2011

In a bash shell script, I want to do something like this:

Code:
if [[ $(ls -ld /some/dir/foo_* | wc -l) -gt 4 ]]; then
rm -rf first_match_of /some/dir/foo_*

[code]....

View 6 Replies View Related

Programming :: Delete Line In File Matching String?

Jan 26, 2010

Quote:Originally Posted by topcatI would like to know how i can write a shell script to delete a line if a particular pattern exists?E.g. I have a text file with multiple lines. Say 1000s. in the following pattern.

username@email.com:149.0.3.4:1
username1@email.com:149.0.3.4:1
username1@email.net:149.0.3.4:1
username1@email.edu:149.0.3.4:1

If the patternusername@email.com exists then the line "username@email.com:149.0.3.4:1 should be deleted from the file.I have a very similar question but I need to delete one line in a file which matches one very precise instance of a string only. Let's assume I have a file composed of thousands of lines and let's call the file chap-secrets. Let's take the following sample entries:

Code:
#USERNAME SERVER PASSWORD IP
pp pptpd blahblah *

[code]....

View 7 Replies View Related

Programming :: Delete Line Containing A Pattern?

Apr 1, 2011

if the given pattern exists in the file with the very next line starting and endingwith the same pattern , delete the line that starts and ends with the given pattern.So upon running on this file

hai people<PATTERN> we had
<PATTERN>a lot of fun<PATTERN>
writing scripts

[code]....

View 6 Replies View Related

Programming :: Sed: Find Pattern And Delete 5 Lines After It?

Mar 23, 2010

I am trying to edit a print file.

For every occurence of the ^L form feed character I need to remove 5 blank lines after it but still keep the ^L.

I am a rare user of sed and am ok with the basics but am struggling with this.

View 4 Replies View Related

General :: Add (not Replacing) A Pattern Match With A Similar Pattern?

Aug 30, 2009

I'm writing a bash script to search html files, and when I find any occurrence of an img src tag like this:

<img src="123-picture-normal.jpg" alt="some random user entered text" border="0">

I want to add a second line below it that looks like:
<img src="123-picture-thumbnail.jpg" alt="some random user entered text" border="0">

All I need to do is duplicate the line but replace "normal" with "thumbnail"

Each file can have multiple img src tags with different numbered jpgs.

I have a feeling this is a job for sed, but I'm struggling with it. Any ideas?

View 2 Replies View Related

Programming :: Search File By Pattern And Then Delete Corresponding Lines In Shell?

Sep 16, 2010

I have such a file(test.txt):

abc 123 456
abc 256 145
axd 125 225

[code]...

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved