grep

R:how to get grep to return the match, rather than the whole string

Hi, I have what is probably a really dumb grep in R question. Apologies, because this seems like it should be so easy - I'm obviously just missing something. I have a vector of strings, let's call it alice. Some of alice is printed out below: T.8EFF.SP.OT1.D5.VSVOVA#4 T.8EFF.SP.OT1.D6.LISOVA#1 T.8EFF.SP.OT1.D6.LISOVA#2 T.8EFF....

search a string in a file as ignoring the lines beginning with #

I want to find a string such as "qwertty=" in a file with "awk" or "grep" but I don't want to see the lines with #. Please see the example grep -ni "qwertty" /aaa/bbb 798:# * qwertty - enable/disable 1222:#qwertty=1 1223:qwertty=2 1224:#qwertty=3 I want to find the line 1223. What should be the search query for this purpose? ...

How Do I grep For non-ASCII Characters in UNIX

I have several very large XML files and I'm trying to find the lines that contain non-ASCII characters. I've tried the following: grep -e "[\x{00FF}-\x{FFFF}]" file.xml But this returns every line in the file, regardless of whether the line contains a character in the range specified. Do I have the syntax wrong or am I doing somethin...

how to substract numbers from levels

Dear SOFers, I would like to cut a vector of values ranging 0-70 to x number of categories, and would like the upper limit of each category. So far, I have tried this using cut() and am trying to extract the limits from levels. I have a list of levels, from which I would like to extract the second number from each level. How can I extra...

Regex to find external links from the html file using grep

hello, From past few days I'm trying to develop a regex that fetch all the external links from the web pages given to it using grep. Here is my grep command grep -h -o -e "\(\(mailto:\|\(\(ht\|f\)tp\(s\?\)\)\)\://\)\{1\}\(.*\?\)" "/mnt/websites_folder/folder_to_search" -r now the grep seem to return everything after the external li...

[Single|Double|Or no] Quotes when using grep?

Grep acts differently depending on what kind of quotes I surround the regex with. I can't seem to get a clear understanding of why this is. Here is an example of the problem: hamiltont$ grep -e show\( test.txt variable.show(); variable.show(a); variable.show(abc, 132); variableshow(); hamiltont$ grep -e "show\(" test.txt gre...

How can I also get an element's index when I grep through an array?

Let's say I have this list: my @list = qw(one two three four five); and I want to grab all the elements containing o. I'd have this: my @containing_o = grep { /o/ } @list; But what would I have to do to also receive an index, or to be able to access the index in grep's body? ...

Capture log4J output with grep

Hi, I know that log4j by default outputs to stderror. I have been capturing the out put of my application with the following command: application_to_run 2> log ; cat log | grep FATAL Is there a way to capture the output without the auxiliary file? ...

Extract a specific string from a curl'd result

Given this curl command: curl --user-agent "fogent" --silent -o page.html "http://www.google.com/search?q=insansiate" * Spelling is intentionally incorrect. I want to grab the suggestion as my result. I want to be able to either grep into the page.html file perhaps with grep -oE or pipe it right from curl and never store a file. T...

Extracting character range form longline with sed or awk or grep?

So i have a 1 long line with characters, for example numbers[1-1024] in one line(no "\n", "\t" and "\b"): 1 2 3 4 5 6 7 8 9 10 11 ... 1024 How do i extract and print characters for example exactly 55 characters after 46? So output would be: 47 48 49 ... 101 Thanks. ...

ack misses results (vs. grep)

I'm sure I'm misunderstanding something about ack's file/directory ignore defaults, but perhaps somebody could shed some light on this for me: mbuck$ grep logout -R app/views/ Binary file app/views/shared/._header.html.erb.bak.swp matches Binary file app/views/shared/._header.html.erb.swp matches app/views/shared/_header.html.erb.bak: <...

How to do a proper search/replace using GREP Regular Expressions in a text editor?

I am trying to run some regular expressions(grep) on a text file of about 4K lines. The main portion that I need replaced looks like this: 1,"An Internet-Ready Resume",1,2,""," And I need it to look like this: <item> <title>An Internet-Ready Resume</title> <category>1</category> <author>2</author> <content> So far, this is what I ...

Bash Script using Grep to search for a pattern in a file

I am writing a bash script to search for a pattern in a file using GREP. I am clueless for why it isnt working. This is the program echo "Enter file name..."; read fname; echo "Enter the search pattern"; read pattern if [ -f $fname ]; then result=`grep -i '$pattern' $fname` echo $result; fi Or is there different approach to do...

Stop Search param in directories by grep immediately after param match

hi friends I use the following command to find under /var some param in my script grep -R "param" /var/* 2>/dev/null |grep -wq "param" my problem is that: after grep find the param in file grep continue to search until all searches under /var/* will completed How to perform stop immediately after grep match the param word For exa...

How do I use grep to extract a specific field value from lines

I have lines in a file which look like the following ....... DisplayName="john" .......... where .... represents variable number of other fields. Using the following grep command, I am able to extract all the lines which have a valid 'DisplayName' field grep DisplayName="[0-9A-Za-z[:space:]]*" e:\test However, I wish to extract j...

grep, xml problem

@ubuntu:/tmp$ cat one.xml <?xml version="1.0" encoding="UTF-8"?> <e2frontendstatus> <e2snrdb> 12.10 dB </e2snrdb> <e2snr> 75 % </e2snr> <e2ber> 0 </e2ber> <e2acg> 99 % </e2acg> </e2frontendstatus> @ubuntu:/tmp$ sed -n -e 's/.*<e2ber>\([0-9][0-9]*\)<\/e2ber>.*...

ack-grep: please help with chars escaping

My goal is to find all "<?=" occurrences with ack. How can I do that? ack "<?=" Doesn't work. Please tell me how can I fix escaping here? ...

Continue to grep for traceroute result with bash

Every night I go through the same process of checking failover systems for our T1's. I essentially go through the following process: Start the failover process. traceroute $server; Once I see it's failed over, I verify that connections work by SSHing into a server. ssh $server; Then once I see it works, I take it off of failover. ...

how to search a file or a text in file in the current folder and in all the subfolders using grep commond?

i have to search for a particular text in files and for that im using grep command but it searches only in current folder.What i want is that using a single grep command i can search a particular thing in the current folder as well as in all of its sub folders.How can i do that??? ...

How can I grep these lines

I want to grep lines starting with a @ and also lines starting with // followed by a line starting with @ Example: //text1 @text2 text3 result: //text1 @text2 How can I do this with grep or any other basic unix tool? ...