grep

grep and sed - replace all instances of a string

I have a bash script I'm writing that greps for a filepath. I want to be able to use the output of the grep to replace each instance of the old filepath with the new filepath. Example: grep -R "/~test/dev/portal" . I want to be able to pipe this output into sed to replace each instance of "/~test/dev/portal/" with "/apps/portal/" (k...

How to grep all the data in a specified col from standard output?

Now i have a standard output which is printed by my program and displayed on the screen. The outputs looks like the following part: Parsing command line string 'InputFile = foreman.qcif'. Parsing command line string 'NumberReferenceFrames = 1'. Parsing command line string 'QPISlice = 24'. Parsing command line string 'QPPSlice = 24'. --...

Compare file with variable list AWK

I'm stumbling over myself trying to get a seemingly simple thing accomplished. I have one file, and one newline delimited string list. File: Dat1 Loc1 Dat2 Loc1 Dat3 Loc1 Dat4 Loc2 Dat5 Loc2 My list is something like this: Dat1 Dat2 Dat3 Dat4 What I am trying to do is compare the ...

What is the powershell equivalent to this bash command?

I'm trying to create a cli command to have TFS check out all files that have a particular string in them. I primarily use cygwin but the tf command has trouble resolving the path when run within the cygwin environment. I figure powershell should be able to do the same thing, but I'm not sure what the equivalent commands to grep and xar...

Grepping complex strings in variables.

All - I am trying to grep for a small string in a much larger string. Both strings are being stored as variables. This code is an example - #!/bin/bash long_str=$(man man) shrt_str="guide" if grep -q $shrt_str $long_str ; then echo "Found it!" fi I don't think variable expansion is working the way I expect it to. I have ...

(grep) Regex to match non-ascii characters?

On linux i have a directory with lots of files. Some of them have nonASCII characters, but they are all valid UTF8. One programme has a bug that prevents it working with nonASCII filenames, I have to find out how many are affected. I was going to do this with find and then do a grep to print the nonASCII characters, and then do a wc -l t...

Handling metacharacters in search strings

I have a user input that would be used in a search string that may contain a metacharacter For e.g. C# or C++ my grep command in a function was: grep -E "$1|$2" test.txt under direct replacement: grep -E "C\+\+|testWord" test.txt grep -E "C\#|testWord" test.txt the first caught the lines fine but not the second. Strangely, # was...

Parse a dhcpd.lease File with Bash

Hi, I Try to parse my dhcpd.lease File with Basel. A typical entry looks like this: lease 192.168.20.4 { starts 6 2009/06/27 00:40:00; ends 6 2009/06/27 12:40:00; hardware ethernet 00:00:00:00:00:00; uid 00:00:00:00:00:00; client-hostname "examle-workstation1"; } All information i get is the MAC and what i want is...

How can I change from a sed to Perl statement in command line?

Hi everyone, I need to search a phrase in multi files and display the results on the screen. grep "EMS" SCALE_* | sed -e "s/SCALE_//" -e "s/_main_.*log:/ /" Since I am not get familiar with sed, I change it to Perl for convenient use. grep "EMS" SCALE_* | perl -e "s/SCALE_//" -e "s/_main_.*log:/ /" or grep "EMS" SCALE_* | perl -...

Default string for grep-find in emacs

I often use the command grep-find in emacs to search through my source files, but it's annying that it always finds matches in temporary files and backup files and so on. The default command for grep-find is: find . -type f -print0 | xargs -0 -e grep -nH -e I know I can modify it before I run it to match my needs but how do I change i...

Help with sed regex: extract text from specific tag

First time sed'er, so be gentle. I have the following text file, 'test_file': <Tag1>not </Tag1><Tag2>working</Tag2> I want to extract the text in between <Tag2> using sed regex, there may be other occurrences of <Tag2> and I would like to extract those also. So far I have this sed based regex: cat test_file | grep -i "Tag2"| sed '...

Oracle: "grep" across multiple columns?

I would like to perform a like or regexp across several columns. These columns contain tags, keywords, etc. Something that's the equivalent of: sqlplus scott/tiger @myquery.sql | grep somestring Right now I have something like select * from foo where c1 || c2 || c3 like '%somestring%' but I'm hoping I can get something a bit mor...

How do I get rid of "--" line separator when using grep with context lines?

I have a text file named compare.txt that I want to extract the single line that follows every line that contains the pattern "nmse_gain_constant". The following command gets me close: grep -A 1 nmse_gain_constant compare.txt | grep -v nmse_gain_constant But this includes a separator "--" line between every line of desired text. Any e...

how to get grep working in Emacs on Windows (EmacsW32)

M-x grep, M-x lgrep, M-x rgrep don't work in EmacsW32 for me. I do M-x lgrep and it says grep is not a command: grep -i -n "hello" * NUL 'grep' is not recognized as an internal or external command, operable program or batch file. Grep finished with no matches found at Sun Jan 31 05:59:06 Also what is that NUL thing? EmacsW32 homepag...

Vim: edit all files that match a certain pattern?

I'm in ~/src I can do git grep _pattern_ and get a list of all *.cpp */hpp files that match this pattern Now, I would like to go through all the files that match the pattern and make edits on them. How do I do this in vim? (basically I want vim to grew through my directory like git grep does, and jump me to the right files). Thanks...

How can i grep a nearer word from a file ?

How can i grep a nearer word from a file ? E.g 04-02-2010 Workingday 05-02-2010 Workingday 06-02-2010 Workingday 07-02-2010 Holiday 08-02-2010 Workingday 09-02-2010 Workingday I stored above data in a file 'feb2010', By this commend i stored date in one variable date=date '+%d-%m-%Y' if date is 06-02-2010 , i want to grep " 0...

Parsing a multiline variable-length log file

I want to be able to utilize a 'grep' or 'pcregrep -M' like solution that parses a log file that fits the following parameters: Each log entry can be multiple lines in length First line of log entry has the key that I want to search for Each key appears on more then one line So in the example below I would want to return every line t...

Find tags doesn’t contain specific attribute (specific word) using grep

How to find all server-side tags (<asp:) that doesn't contains attribute runat in my Visual Studio 2008 / MonoDevelop solution using grep? ...

editing text files with perl

I'm trying to edit a text file that looks like this: TYPE=Ethernet HWADDR=00:.... IPV6INIT=no MTU=1500 IPADDR=192.168.2.247 ... (Its actually the /etc/sysconfig/network-scripts/ifcfg- file on red hat Linux) Instead of reading and rewriting the file each time I want to modify it, I figured I could use grep, sed, awk or the native text ...

Use grep in Mac Terminal

I use Terminal in Mac with the following command: df -lak | grep File||disk02 what I want to use this script to get the header of df command (disk space) and the line with disk02 only. I think '|' is a char in grep as or logic. However, since I am using grep in Terminal, the char '|' also means pipe. Therefore I tried to use '||' t...