FAQ Database Discussion Community


How do I grep multiple possible extensions recursively

regex,grep
This question is different from other grep pattern matching questions because we're looking for a large number of file extensions, and thus the following from this question will be too long and tedious to type: grep -r -i --include '*.ade' --include '*.adp' ... CP_Image ~/path[12345] I was trying to email...

Can't get expression working against grep or findstr

regex,grep
I can get my regex working here, but can't get it working in grep or findstr Tried using it straight: findstr /r "(232323)(\d*)(1313)" * grep "(232323)(\d*)(1313)" * ...

Cut specific words matching a pattern from a text file

shell,grep,cut
I am trying to extract words from a text file matching a pattern using shell script. For example if a line contains This is a sample text to illustrate my scenario text=info id=2342 Second line to illustrate text=sample id=q2312 I want the output to be like text=info id=2342 text=sample id=q2312...

Python command(s) to find unique names in long list

python,bash,grep
I have a data file which lists dates (indicated by the line containing .) and names followed by a number: 2015.05.22 nameA 15 nameB 32 2015.05.20 nameA 2 nameC 26 This list file is quite long (~97k lines and growing daily) and I want to (quickly) get all unique names...

How to copy matches from an extremely large file if it contains no newlines?

python,linux,bash,perl,grep
The problem is I cannot avoid working with extremely big files which contain no newlines in them: <a>text1</a>...gigabytes of data here, all in one single line...[a text to extract b> What should I do if I want to copy matches from this file (putting every match in a separate line,...

Regex pattern without one case

regex,bash,sed,grep
I would like to remove some strings from filename. I want to remove every string in bracket but not if there is a string "remix" or "Remix" or "REMIX" Now I have got sed "s/\s*\(\s?[A-z0-9. ]*\)//g" but how to exclude cases when there is remix in string?...

Grep exact match returns matches with periods, spaces, hyphens, etc

bash,shell,grep
... | grep -w "2015" 2015%kjlia hi 2015.halteriafu etc-2015 ... I want my grep to return lines with "2015" exact matches. In original data there can be any characters before and after 2015. The above only omitted a few lines like ..yguj2015vj.. with 2015 having adjacent alphanumeric character....

check difference via minus between two file

linux,shell,awk,sed,grep
I have two files test1 and test2 test1 foo bar hello world test2 bar world hello and I really want to obtain foo here, could anybody help me? please .....

Remove full url's from text file using unix awk/sed/grep

bash,unix,awk,sed,grep
I have a text file that in the form of tweets and I am having issues removing the full url's. An example of the textfile: index.html: this is a tweet that has info. http://google.com this is a tweet that has an image. pic.twitter.com/a2y4H1b2Jq I would like to create a new...

How do I make findstr show the full file path inline?

command-line,path,grep,dos,findstr
When I use grep I get a list of matching results with the full file path for all the child subdirectories. When i do this with findstr - I don't get the inline results. My question is: How do I make findstr show the full file path inline?...

grep/sed replace no match with blank space

bash,awk,sed,grep
Example of a file I'm greping information in: name : server1 description : webserver memory : 32gb name : server2 memory : 128gb name : server3 description : appserver I'm doing something like this : cat myfile | egrep -w "name|description|memory" | awk -F" " '{print $3}' >> myfile2 In...

How do I grep GZ files to extract PNG files?

grep,png,gz
Ok, so I have a tone of .GZ files in a folder, and I'm looking to recursively look through each one of them and extract all the PNG files into another destination folder. How would I do that? EDIT: I've been using this command from the terminal to find a...

Grep between some period

linux,logging,grep
I have large log file, in which each record starts with date, formatted like this: [2014-10-06 07:03:49] What`s the easiest way to grep by specific period of time ? I want to grep by specific date range, for example, taking the example date, from 06.10.2014 to 08.10.2014. ...

Git > diffs filtered, show only certain changed classes/files

git,filter,grep,diff,git-log
I have 2 versions of a software (i.e. tag 4.1 and tag 4.2). Now I want to filter out in which java classes of version 4.1 there were fixed bugs. If I enter git diff r4.1 r4.2 --name-only > patch.csv I get a list of all changed classes from version...

Modern-day Unix tools are written in what programming language? [closed]

c,linux,bash,unix,grep
Here is an example of using two Unix tools: ls | grep "MMC" ls and grep are two Unix tools. I believe that both ls and grep are written in C. (Correct me if I'm wrong) What programming language is used to implement modern-day Unix tools? Are modern-day Unix tools...

Show Results' line numbers using grep

linux,bash,grep,formatting,line
how i can show the result of my grep command with incremental numbers before them , i'm not talking about using -n or -nr to show where is my string located in that files. i'm talking about something like this : grep foo *.* result should be like this :...

How to pass url to wget

grep,pipe,wget
If I have a document with many links and I want to download especially one picture with the name: www.website.de/picture/example_2015-06-15.jpeg. How can I write a command that downloads me automatically exactly this one I extracted out of my document. My idea would be this but I'll get a failure message...

Grep-ing non-seekable file

linux,bash,grep,stdin
How does grep allocate buffer for reading lines when non-seekable files like devices, sockets, pipes or fifos are used? I tried doing the following grep hello - I gave as input a single line containing around 9484 characters including space. Grep processed some characters (I guess around 4K) and just...

grep and return line continuations?

regex,grep,pcre,pcregrep
I want grep to return results through line continuations, ie input file like: $ cat input.txt abba \ jjjj \ nnnn $ grep "abba ?" input.txt abba jjjj nnnn I can't seem to get it working....

group characters within square brackets in grep

regex,grep
I have a file named zone-file with following content: c3-Tx-Msi-US IN CNAME c3-L123-Tx-Msi-US c3-L123-Tx-Msi-US IN A 192.0.2.11 c5-Ny-Msi-US IN CNAME c5-L123-Ny-Msi-US c5-L123-Ny-Msi-US IN A 192.0.2.33 c1-Ny-Gre-SE IN CNAME c1-L123-Ny-Gre-SE c1-L123-Ny-Gre-SE IN A 192.0.2.89 r6-Ms-Msi-UK IN CNAME r6-L123-Ms-Msi-UK r6-L123-Ms-Msi-UK IN A 192.0.2.16 c1-St-Rec-SE IN CNAME c1-L123-St-Rec-SE c1-L123-St-Rec-SE IN A 192.0.2.1 I...

How to extract single-/multiline regex-matching items from an unpredictably formatted file and put each one in a single line into output file?

linux,shell,unix,replace,grep
I have a very huge file which looks like this: <a>text</a>text blah <b>data1</b>abc<b>data2</b> <b>data3</b>blahblah <c>text</c> <d>text</d> <x>blahblah<b>data4 data5 data6</b> <b>data7 </x> That is, its formatting is unpredictable. I need to extract each <b>...</b> item (it might contain multiline text!) and put every one of them in a single separate line....

Logical OR in GLOB during grep --include/--exclude

bash,grep
In the Ubuntu terminal, I would like to grep all files with (or excluding) extension .foo and .bar for the phrase 'foobar'. I've read this advice for creating a GLOB with a logical or, and tried a few combinations but none seem to work: rgrep "foobar" --include "*.foo|*.bar" rgrep "foobar"...

Using pure Python over grep?

python,grep,sublimetext3
I am not familiar with grep as I've always been on a Windows system so when someone suggested I add these lines to my code, I'm a little confused... grep = 'grep -E \[email protected]*{}\' * -l'.format(name) proc = Popen(grep, shell=True, cwd=info['path'], stdout=PIPE, stderr=PIPE) From my understanding, this is trying to...

Grep string start with . or whitespace

bash,grep,prefix
I'm running a script that get an argument $1 I want to find all strings that start with either space or . before that argument. and end with either . or % ex: if $1 is Table1 then 1) "Table1" 2) " Table1" 3) ".Table1" 4) "Table1." 5) ".Table1." 6)...

Linux search for a string in a line but replace another string in that line

linux,shell,sed,grep
If test.txt file is GREEN Volks RUNNING GREEN Audi STOPPED GREEN Merc RUNNING I can grep STOPPED and replace it with sed as following grep "STOPPED" test.txt |sed 's/^GREEN/RED/g' Which returns following output RED Audi STOPPED But instead I would like try something like sed -i 's/^GREEN/RED/g'| grep "STOPPED" test.txt...

Sorting unique elements column-wise in a text-file

regex,linux,awk,sed,grep
I have a tab delimited file like chr1 4359314 4361314 Rp1 - chr1 4492735 4494735 Sox17 - chr1 4495330 4498354 Sox17,Sox17,Sox17,Sox17,Sox17,Sox17 -,-,-,-,-,- chr1 4784698 4786739 Mrpl15,Mrpl15,Mrpl15,Mrpl15 -,-,-,- chr1 4806788 4809237 Lypla1,Lypla1,Lypla1,RP24-426M1.3,Lypla1,Lypla1,Lypla1,Lypla1 +,+,+,+,+,+,+,+ chr1 4856814 4859038 Tcea1,Tcea1 +,+ chr1 5017735 5020539 Rgs20,Rgs20,Rgs20 -,-,- chr1 5069018 5071285 Atp6v1h,Rgs20,Rgs20 +,-,- chr1 5082080 5084154...

Delete first characters off of a line in a file with awk or grep

bash,awk,grep
I'm attempting to remove a certain pattern from a line, but not the entire line itself. An example would be: Original: user=dannyBoy Desired: dannyBoy I have a file that is full of lines like that, so I was wondering how I would be able to cut a specific part of...

Deleting duplicate lines along with original

perl,awk,sed,grep,tcl
I have a file which contains patterns on each line, some of which are repeating. i want only those patterns which do not repeat. So, I want to remove all repeating data along with the original pattern. I cannot use sort since i want the patterns to be in same...

grep part of dataframe and use as title in plot

r,plot,grep
how do I get the name of a dataframe say mydf.mtcars<-mtcars and grep everything after the . i.e. mtcars and then use this as the title in a plot? It would be the equivalent of doing plot(mydf.mtcars,main="mydf") Thanks...

Getting the first match with grep

bash,grep
I have a bash function that goes through a list of files and greps for a certain word and writes it into a file. The problem is I get every instance of the word, I just want to get the first instance. I came across a solution by adding head...

grep and sed - find function calls in files

bash,command-line,sed,grep
I need to find usages of class methods in project folder (for refactoring). Now I'm search with grep -nr "className." .. And get list like: file1.js:874: var x = className.method1() + m; file5.js:330: console.log(className.method2()); etc... My goal is to get only methods that used in files without any code around....

Grep capping size of results lines, for multiple grep phrases?

linux,bash,grep
I am grepping for terms like this: grep 'term1\|term2\|term3\|term4' and I want to say, for all lines which are found, cap the results to 100 characters. I found some examples how to do this when searching for one term, but none accommodating the OR-ing of search terms....

grep in R does not find rows when terms are ORed together

regex,r,grep
I am new to R. I am working on a very large dataset with 1M+ rows and 1000+ columns that needs serious data cleaning. I have managed to clean the data for most part, however that has left me with some messy repetitive code. I am trying to use grep...

Extract lines between A and (B or C), containing D

bash,perl,awk,sed,grep
I need to extract text between A and (B or C) patterns, that contains D pattern inside. For example I have a file and need to extract all between "proc sql" and ("quit" or "run"), containing "index" inside. proc sql bla-bla-bla index=10; quit proc sql bla-bla-bla quit; proc sql index=10;...

How to grep for value in a key-value store from plain text

linux,shell,unix,grep
Given a plain text file containing FOO=foo BAR=bar BAZ=baz How do we grep for the value using the key?...

R character match and rank

r,grep,pattern-matching,string-matching
I have a character vector var1 <- c("pine tree", "dense forest", "red fruits", "green fruits", "clean water", "pine") and a list var2 <- list(c("tall tree", "fruits", "star"), c("tree tall", "pine tree", "tree pine", "black forest", "water"), c("apple", "orange", "grapes")) I want to match words in var1 with elements in var2,...

Add blank line before a certain phrase in a text file in Linux?

linux,text,grep,kali-linux
I'm using Kali Linux, trying to sort out some input from Nmap. Basically, I ran a scan from NMap, and need to extract specific pieces of information from it. I've got it to show everything I need using the following command: cat discovery.txt | grep 'Nmap scan report for\|Service Info:...

bash script grep using variable fails to find result that actually does exist

bash,curl,sed,grep,carriage-return
I have a bash script that iterates over a list of links, curl's down an html page per link, greps for a particular string format (syntax is: CVE-####-####), removes the surrounding html tags (this is a consistent format, no special case handling necessary), searches a changelog file for the resulting...

Regular expression to match string operator

regex,bash,grep
I am trying to create a regular expression that matches the operator ^ (xor) as long as it is acting as an operator between two strings and not beeing part of an string. For example, having a file with these two lines: 'asdfasdf'; 'asdfasd'^'asdflkj'; ['asdf', '^', 'asdf']; only the first...

Awk Sed Grep parsing text file to match a pattern

linux,bash,awk,sed,grep
I need to run this from command prompt to display only those lines that match the pattern after the words beside the sign# Example #IP. So if I'm looking for IP, I want to print the lines under the section #IP. In this case I will print only 3 lines....

Loop through directories, check if string exists in one file, move another file

bash,grep
I'm working on a bash script that should do the following: for every directory beginning with Event_*, (in cat eventList), cd into the directory, and if the string "ZJ.ROT" exists in the file *.mcp, I want to copy the file "ROT" to another directory. In simpler terms: loop through directories:...

Find lines by pattern, leave only pattern but leave unmatched lines as they are

regex,awk,sed,grep,pipeline
So there is an input file res.txt like this processing file 0x8001.values channel 1: 123 channel 2: 234 channel 3: 345 processing file 0x8002.values channel 1: 456 channel 2: 567 channel 3: 678 I have a pattern like this 0x[0-9a-f][0-9a-f][0-9a-f][0-9a-f] Using, for example, grep -o "0x[0-9a-f][0-9a-f][0-9a-f][0-9a-f]" res.txt I can get...

Get most popular domains from log

shell,grep
I am trying to get most popular domain from a log file The log format is like this 197.123.43.59, 27/May/2015:01:00:11 -0600, https://m.facebook.com/ I am interested only with the domain and i want an output as follows XXXX facebook.com where XXXX is the number of similar entries in logs A one...

Perl return array from multidimensional array

arrays,perl,multidimensional-array,reference,grep
I've got this multidimensional array: @valid_values = (["val00", "val01", "val02"], ["val10", "val11", "val12"]); Via grep I want to check, if a certain value exists within the first array of the multidimensional array. I've tried something like this: if (grep $_ eq $check_value, @valid_values[0]) {print "ok\n"} This doesn't work though. I've...

Matching string inside file and returning result

regex,string,bash,shell,grep
I've got a few peculiar issues with trying to search for a string inside of a .db file. The way I tried was by using grep, which does apparently find the string(s), although this is the output: $ grep "ext" *.db Binary file enormous.db matches There are a couple problems...

Bash - how to check the string length using grep?

bash,grep
I have a lot of Teradata SQL files. The example file look like below: create multiset volatile table abcde_fghijk_lmnop as( select a.oppnl3_budssstr as nip, from T45_BACKJJU_33KUT.BRANDFO9 a ) with data on commit preserve rows; create multiset volatile table mari_lee as( select b.getter3, from maleno_fugi75_pratq b ) with data on commit...

Pipe output to egrep function

bash,grep
I'm trying to define a bash function, highlight, that I can use to highlight search terms in the output of a previous command. When I do this from the terminal, it works fine as follows: # highlight all occurrences of bar in file foo cat foo | egrep '(bar|$)' Yes,...

filter table for abundance in at least 20 % of the samples

table,awk,grep
I have a huge table tab separated like the one below: the first row is the subject list while the other rows are my counts. KEGGAnnotation a b c d e f g h i l m n o p q r s t u v z w ee wr...

Remove specific (complex) line from MANY files (sed?)

regex,bash,sed,grep
Server was hacked, every php file on the server now starts with malicious code: <?php if(!isset($GLOBALS["\x61\156\x75\156\x61"])) { $ua=strtolower($_SERVER["\x48\124\x54\120\x5f\125\x53\105\x52\137\x41\107\x45\116\x54"]); if ((! strstr($ua,"\x6d\163\x69\145")) and (! strstr($ua,"\x72\166\x3a\61\x31"))) $GLOBALS["\x61\156\x75\156\x61"]=1; } ?><?php $zdsnpbzghe =...

How to split dataframe column in R

r,grep,substring
I have a column in a dataframe called parm_value that I would like to split into two columns, lower and upper bound based on the position of the underscore in the field. I have been trying to use a combination of grep and substring with no success Current dataframe format:...

Linux Check if string exists as separate word (not as substring of another)

linux,string,bash,shell,grep
I have a file that contains strings, and I would like to check if a string exists in that file as a separate word. example: string = rambox file that contains "rambox": initrd=yahya/rambox/initramfs11.cpio.gz rambox ramdisk_size=5242880 ... "grep" command will tell that "rambox" exists file not containing "rambox" initrd=yahya/rambox/initramfs11.cpio.gz ramdisk_size=5242880 ......

Use grep to find either of two strings without changing the order of the lines?

regex,grep,protein-database
I'm sure this has been asked but I can't find it so my apologies for redundancy. I want to use grep or egrep to find every line that has either ' P ' or ' CA ' in them and pipe them to a new file. I can easily do...

Bash check if grep matches string

bash,grep
I am writing a bash script that checks every 5 minutes if there is from an IP address 100 or more invalid passwords (bruteforce attack) attempts. The following script works: blockIPs="$(cat /var/log/secure | grep "Failed password for" | grep -v "invalid" | awk {'print $11'} | sort | uniq -c...

regex to find lines starting with `*` and ending with `)` in eclipse using regex search

regex,shell,grep
I am trying to use this regular expressing in Eclipse to find the lines mentioned below. I have a text file text.txt: teeet() *test() *test * () test asdgaer () * test() I want to find the regex to find all the lines that starts with * and ends with...

How to grep two patterns at once

grep
Often times I have to do so commandline thing where I pipe to grep and want matches for two different expressions. ( An OR match A OR B. ) For example I want to grep the output of generate_out for either foo[0-9]+ or bar[0-9]+. I of course could just execute...

How to search for a text in specific files in unix

unix,grep
I am using Ubuntu machine and tried with below commands to search for a text: This command to check if the word is present in a given directory recursively: 1) Here <hello> is the word which I am search for and it searches recursively in all files starting from current...

Using awk and grep command in for loop

shell,awk,grep,ksh
Consider below code snippet: #! /bin/ksh for i in `grep "ProcessOrderWebService-N" Orders.Log | grep "::stringFromNetwork = 600001" | awk -F',' '{print $1}'`; do echo $i; done; 2015-05-26 10:20:10 2015-05-26 10:20:49 2015-05-26 10:21:45 From the command prompt, when I run the command: grep "ProcessOrderWebService-N" Orders.Log | grep "::stringFromNetwork = 600001" |...

How to get row count between two words in Linux

linux,unix,awk,grep
Below is the pattern of my source files: Col1 Col2 col3 colN START-OF-DATA val1|val2|val3|valN val1|val2|val3|valN val1|val2|val3|valN val1|val2|val3|valN END-OF-DATA TIMEFINISHED=Mon Apr 21 20:28:55 EDT 2014 END-OF-FILE I want to find out the row count between START-OF-DATA and END-OF-DATA. Initially I had to do it for one file so I just used...

Bash, Using grep, sed or awk to extract section of text and then match

bash,awk,sed,grep
I have a text file and want to extract all interfaces matching "blue" random text random text random text random text random text int 1 random text blue random text random text int 2 random text random text red random text int 3 random text random text random text blue...

How do I convert from using `grep -P` to `grep -E`?

linux,osx,ubuntu,grep,bsd
I have a script that we use on Ubuntu (Linux) and I'd like to convert it to be used on both Ubuntu (Linux) and MacOS X. grep on Linux is different than grep on FreeBSD (i.e. MacOS X); grep on MacOS X doesn't support the -P option. Unfortunately, using the...

Why does grep matches all the lines no matter what the pattern

regex,bash,grep
I'm having a problem using grep. I have a file http://pastebin.com/HxAcciCa that I want to check for certain patterns. And when I"m trying to search for it grep returns all the lines provided that the pattern already exists in the given file. To explain more this is the code that...

grep exact match excluding certain terms

regex,r,grep
Help apprecited. I've got a long list of column names in a vector, where the pattern is like this: cols <-c('a35-male-x1','a35-female-x2','a16-male-t0','a65-female-t7',...) I've tried using grep to find the columns with 'male' matches, but exclude the female ones. grep(pattern='male',cols) will get all 4 entries. Is there a simple way to get...

R match whole words in phrases

r,string,grep,pattern-matching
I have a character vector var1 <- c("pine tree", "forest", "fruits", "water") and a list var2 <- list(c("tree", "house", "star"), c("house", "tree", "pine tree", "tree pine", "dense forest"), c("apple", "orange", "grapes")) I want to match words in var1 with words in var2, and extract the maximum matching element in var2....

Search File with SSL in Linux

linux,unix,grep
I want to search All .java files in current directory and subdirectories that ends with .java and have text "SSL" in that file. Any help on this?? I tried grep -rnq -e "SSL" but its taking so much time. Thanks in advance.

Discrepancy between linux grep and Ruby's scan results

ruby,regex,string,grep
I have a list of DNA sequences (one per line): ACTGCTCGGGGG..... CGCTCGCTTCTCTC... etc Most sequences contain two specific motifs, one close to the begining and one closer to the end. I am extracting the sequences inbetween: with grep: grep "motif1.*motif2" inputfile > outputfile in ruby with scan, where sequences is...

(bash) check if IP in subnet range file

regex,linux,bash,shell,grep
I've a list of subnet range in a file: 2.32.0.0-2.47.255.255-255.240.0.0 2.112.0.0-2.119.255.255-255.248.0.0 2.156.0.0-2.159.255.255-255.252.0.0 2.192.0.0-2.199.255.255-255.248.0.0 ... (The file format is: {startip}-{endip}-{netmask}) I need check if an IP is included in one of the subnet in the file....

Grep specific part of string from another file

awk,grep
I want to grep the first three digits of numbers in 1.txt from the first three digits after zeros in 2.txt. cat 1.txt 23456 12345 6789 cat 2.txt 20000023485 xxx888 20000012356 xxx888 20000067234 xxx234 Expected output 20000023485 xxx888 20000012356 xxx888 ...

How to extract table data from PDF as CSV from the command line?

pdf,grep,pdftotext
I want to extract all rows from here while ignoring the column headers as well as all page headers, i.e. Supported Devices. pdftotext -layout DAC06E7D1302B790429AF6E84696FCFAB20B.pdf - \ | sed '$d' \ | sed -r 's/ +/,/g; s/ //g' \ > output.csv The resulting file should be in CSV spreadsheet format...

searching through text file in terminal

linux,unix,awk,grep,less
Hi this might be a basic question for many, but it has however managed to eat a couple of hours of my time. I have large data file as an output from running a script. The file contains around 15 columns and around 100,000 rows. I wish to search through...

fetch specific string from data

regex,grep
i have some data FON2_ORYSJ|FON2|FON4|LOC_Os11g38270|Os11g0595400 A1IGU8_ORYSJ|OsF5HL|Os06g0349700 A1IGU8_ORYSJ|OsF5HL|Os06g0349700 MTND1_ORYSJ|ARD1|SIP2|LOC_Os10g28350|Os10g0419400|OSJNBa0006I13.11 MTND1_ORYSJ|ARD1|SIP2|LOC_Os10g28350|Os10g0419400|OSJNBa0006I13.11 MTND1_ORYSJ|ARD1|SIP2|LOC_Os10g28350|Os10g0419400|OSJNBa0006I13.11 MTND1_ORYSJ|ARD1|SIP2|LOC_Os10g28350|Os10g0419400|OSJNBa0006I13.11 i need to fetch the LOC_OS* and Os* id separately. the output should be like LOC_Os11g38270 LOC_Os10g28350 LOC_Os10g28350...

Grep includes values that I have not specified

r,grep
I'm trying to get a list of rows based on some column values, but when I grep for the values, the returned list of rows includes rows with values that I have not specified. Specifically: I want rows in which df$likert_classification != NA, and df$variable is 'picture_trained', 'unambig_picture_proportion' or 'ambig_picture_proportion'....

Extract lines from File2 already found File1

linux,text,awk,sed,grep
Using linux commandline, i need to output the lines from text file2 that are already found in file1. File1: C A G E B D H F File2: N I H J K M D L A Output: A D H Thanks!...

Bash scripting grep variable from multilined json?

json,bash,grep
I have a JSON file that has many instances like this..: { "SensorApp": "Open Hardware Monitor", "SensorClass": "Temperature", "SensorName": "Intel Core i7-4790: CPU Core #4", "SensorValue": "31", "SensorUnit": "C", "SensorUpdateTime": 0 }, { "SensorApp": "Open Hardware Monitor", "SensorClass": "Temperature", "SensorName": "Intel Core i7-4790: CPU Package", "SensorValue": "32", "SensorUnit": "C", "SensorUpdateTime":...

How to grep a shell variable to match end of line?

regex,bash,shell,grep
How can I match a bash variable in the end of the line? The code below can do that for a number in the end: grep '[0-9]$' But in my case the number is a variable. I was hoping something like grep '{$i}$' where $i is my variable, would work,...

how to remove two lines above after we find a match in a file in BASH?

bash,awk,sed,grep
I have a file that contain data like: 123 456 789 I want to delete the above two lines (123 and 456) when I find a match 789. Is it possible to do it with sed or awk? Please Help...

search a string only inside a function definetion

perl,unix,awk,sed,grep
Is there any way to search a string only inside a function definition. I mean to say suppose there is a c program file a.c , in which there is definition of several functions are present , but i want output of search only when that string present inside specific...

grep string between two other strings as delimiters

regex,powershell,grep
I have to do a report on how many times a certain CSS class appears in the content of our pages (over 10k pages). The trouble is, the header and footer contains that class, so a grep returns every single page. So, how do I grep for content? EDIT: I...

Delete some lines from text using Linux command

linux,shell,sed,grep,pattern-matching
I know how to match text using regex patterns but not how to manipulate them. I have used grep to match and extract lines from a text file, but I want to remove those lines from the text. How can I achieve this without having to write a python or...

Grepping second pattern after matching first pattern

regex,perl,sed,grep,tcl
Is there any grep/sed option which will allow me to match a pattern after matching another pattern? For example: Input file (foos are variable patterns starting with 0 mixed with random numbers preceded by # in front): 0foo1 0foo2 0foo3 \#89888 0foo4 0foo5 \#98980 0foo6 So once I try to...

Can I use grep in place of awk?

android,bash,shell,grep,ksh
I'm attempting to take this output (linebreak added for readability, please discard on reading): mCurrentFocus=Window{167ead2f u0 com.google.android.googlequicksearchbox/com.google.android.launcher.GEL} and extract this: com.google.android.googlequicksearchbox using only the tools natively available in Android, such as grep. The following commands will do it, but they use cut rev and awk. dumpsys window windows | grep...

grep first n rows, return file name only

regex,linux,search,grep
I can do the following to search for what I need and return the file name: grep -l "mysearchstring" ./*.xml However the files I am searching are huge so this takes forever. The string I am searching will appear in the first 200 rows so how can I search only...

Extracting CREATE TABLE definitions from MySQL dump?

mysql,regex,grep,hex-editors
I have a MySQL dump file over 1 terabyte big. I need to extract the CREATE TABLE statements from it so I can provide the table definitions. I purchased Hex Editor Neo but I'm kind of disappointed I did. I created a regex CREATE\s+TABLE(.|\s)*?(?=ENGINE=InnoDB) to extract the CREATE TABLE clause,...

Count overlapping occurences of a repeated string using grep/linux/bash

linux,bash,shell,sed,grep
I'm trying to count occurences of a repeated string. Eg. echo 'joebobtomtomtomjoebobmike' | grep -o 'tomtom' | wc -l This outputs 1, but obviously the string 'tomtom' fits twice here. How can I make it so it counts both occurences? Thanks!...

how to grep lines according to 6th field contents

linux,bash,awk,sed,grep
I would like to know how to filter lines according to the mem usage: I would like to be able to find only the PIDs that (RES mem usage) exceed 5GB Explicitly, I have the following lines 20697 user 20 0 357m 24m 19m S 19.0 0.1 887:15.00 pulseaudio 13017...

Match line not containing a pattern in BBEdit with Grep

grep,bbedit
I am having trouble finding the correct grep expression for not matching entire lines in BBEdit that do not contain a date, despite having found many "match ... not containing" topics on this on the web... I have this text document: Some Text Some more text,even more text,2015-06-17,2015-06-20 A third...

How to describe an optional negative lookahead in regular expression?

regex,grep,lookahead
I like to get the appointment description of calender entries which a program called khal outputs by using grep. The output of khal looks like this: 20:30-22:30 13.05.2015: Manfred treffen Repeat: FREQ=WEEKLY;BYDAY=WE;WKST=MO 09.05. - 12.05.2015: Britt Besuch In the example I would like to match Manfred treffen and Britt Besuch....

find string including quotation marks using grep

grep,pattern-matching,quotes
How can I find a string which includes quotation marks with grep? I tried a backslash to escape but this doesn't work. For example search for the string "localStorage['api']". I tried: grep -r "localStorage['api']" /path grep -r "localStorage[\'api\']" /path ...

How to read from STDIN in python from a piped grep output [duplicate]

python,linux,bash,grep
This question already has an answer here: How do you read from stdin in Python? 13 answers Let's say I have a text file and grep "@" file.txt returns: (1) preparing corpus @ Tue Apr 28 20:19:31 CEST 2015 (1.0) selecting factors @ Tue Apr 28 20:19:31 CEST 2015...

Whole-word matching on a body of text, given a list of words

regex,string,bash,shell,grep
Note: Before I get down to business, I'd like to point out some other SO posts that didn't quite answer my question and are not duplicates of this one: How to grep with a list of words How to grep the exact match how to grep for the whole word...

Print the results of a grep to a csv file

linux,grep
I am trying to print the results of grep to a CSV file. When I run this command grep FILENAME * in my directory I get this result : B140509184-#-02Jun2015-#-11:00-#-12:00-#-LT4-UGW-MAJAZ-#-I-#-CMAP-#-P-45088966.lif: FILENAME A20150602.0835+0400-0840+0400_DXB-GGSN-V9-PGP-16.xml. What I want is to print the FILENAME part to a csv. Below is what I have tried...

Parse IP and Download-Total from mikrotik

regex,bash,sed,grep
I wanna extract IP and download-total from mikrotik command /queue simple print stat Here's some example : 0 name="101" target=192.168.10.101/32 rate=0bps/0bps total-rate=0bps packet-rate=0/0 total-packet-rate=0 queued-bytes=0/0 total-queued-bytes=0 queued-packets=0/0 total-queued-packets=0 bytes=17574842/389197663 total-bytes=0 packets=191226/308561 total-packets=0 dropped=9/5899 total-dropped=0 1 name="102" target=192.168.10.102/32 rate=0bps/0bps total-rate=0bps packet-rate=0/0 total-packet-rate=0 queued-bytes=0/0 total-queued-bytes=0...

Command Line: manipulating file names; grep?

command-line,grep,renaming
I currently have a directory of files with date based names in the format mmddyy: nxd060815a.html nxd060915a.html nxd061015a.html and would like to change file name format to yyyy-mm-dd: nxd2015-06-08a.html nxd2015-06-09a.html nxd2015-06-10a.html How would I do this from the command line? Any help is appreciated....

filter file with specift words linux

linux,bash,grep
I have files in which the first column is an ID, and the second column is an option, like this: $ cat file.txt 1234;m11 6758;m11;m14 8796;mm14 0303;m11 and I need to create a files with the IDs depending with the option. It is to say: file_m11.txt => (1234,0303) file_m11_m14 =>...

Linux -> Terminal command -> Grep -> Expressions / Exceptions related to symbol

linux,bash,shell,grep
Simply: I have problem with command which should print me lines containing any of those two expressions: "king" , "king's son". This is where I got so far: grep -w "king's son\|king" frog.txt It does work but it include "king's" which should not happen. Adding -v grep "king's" does not...

Search for unicode values in character string

r,unicode,grep,gsub
I am trying to identify unique unicode values in a data frame composed of character strings. I have tried using the grep function, however I encounter the following error Error: '\U' used without hex digits in character string starting ""\U" A example data frame time sender message 1 2012-12-04 13:40:00...

How to grep a string in a program?

c,linux,io,grep,pipe
#include <stdlib.h> int foo(char *str_buf_to_grep) { // How to write the following line correctly? return system("??? str_buf_to_grep ??? | grep mykeyword"); } Description: The str_buf_to_grep is given in any way, which might be the content of a text file, and might be very long and complex, even contains special characters,...

Command to replace string in a file

string,replace,sed,grep,command
I want to replace a string in a file using command, but the thing is the string is such "https": false, I want to change it to "https": true, and vice versa. is there any way to accomplish this thru command? Am developing auto script so whenever a user logins...

Inverse of grep's A [duplicate]

linux,shell,grep
This question already has an answer here: sed or awk: delete n lines following a pattern 4 answers I know that I can print the "next" line of a match with grep, with -A1, but what about the inverse of that? I mean, "hide the next line after a...

how to deletes line from a text file that are taken from another file [duplicate]

shell,awk,sed,grep,sh
This question already has an answer here: Remove duplicates from text file based on second text file 4 answers I have a data.txt file with a lot of lines in it and a lines.txt that contains some lines. I want to delete all lines from data.txt that match any...

Mac OS X remove line from multiple files

osx,grep
I'm attempting to remove a line from several hundred files. The following does exactly what I need but, it doesn't save changes (as expected). $ grep -v meow src/files I've seen that appending > to the end of a given command will specify where the output buffer should save but,...