grep

unix script to count the number of characters between particular xml tags

Hi I am trying to create a script that will count the number of characters between xml tags and idealy group by these values before returning the variations: eg <CONTEXT_1>aaaa<CONTEXT_1> <CONTEXT_2>bb<CONTEXT_2> <CONTEXT_2>dfgh<CONTEXT_2> <CONTEXT_6>bb<CONTEXT_6> <CONTEXT_1>bbbb<CONTEXT_1> the result of this would be <CONTEXT_1> 4...

Locate files which ONLY contain printable characters in bash script

Hi there, I'm trying to write a bash script that looks at a directory full of files and categorises them as either plaintext or binary. A file is plaintext if it ONLY contains plaintext characters, otherwise it is binary. So far I have tried the following permutations of grep: #!/bin/bash FILES=`ls` for i in $FILES do ########GREP...

How to grep for the dollar symbol ($) ?

% cat temp $$$ hello1 $$ hello2 hello3 ## hello4 hello5 $$$ % cat temp | grep "$$$" Illegal variable name. % cat temp | grep "\$\$\$" Variable name must contain alphanumeric characters. % I want to grep for $$$ and I expect the result to be % cat temp | grep <what should go here?> $$$ hello1 hello5 $$$ % To differentia...

does utf-8 encoding messes file globbing and grep'ing?

I'm playing with bash, experiencing with utf-8 encoding. I'm new to unicode. The following command (well, their output) surprises me : $ locale LANG="fr_FR.UTF-8" LC_COLLATE="fr_FR.UTF-8" LC_CTYPE="fr_FR.UTF-8" LC_MESSAGES="fr_FR.UTF-8" LC_MONETARY="fr_FR.UTF-8" LC_NUMERIC="fr_FR.UTF-8" LC_TIME="fr_FR.UTF-8" LC_ALL= ...

How can I substitute one substring for another in Perl?

I have a file and a list of string pairs which I get from another file. I need substitute the first string of the pair with the second one, and do this for each pair. Is there more efficient/simple way to do this (using Perl, grep, sed or other), then running a separate regexp substitution for each pair of values? ...

Regex process using cut(Linux)(sh)

Hello people, I'm having a problem with regex in using the command sh cute, the problem is that I want to show all processes that start with g and just show the command, but do not know, help me please? To do this I use the command: ps aux | grep g but this show all process who contains the letter g and i need who start with g and c...

using grep or awk to find files that contain both "a" and "b" that are on different lines

Is there a way to use grep or awk to find text files that contain both e.g. "a" and "b" but in this case "a" and "b" are on different lines? ...

How to find/fix files with MIXED line endings (0x0d 0x0d 0x0a)

I know I can "probably" fix them by using "flip -u" (cygwin flip) which basically removes one of the 0xd's leaving the file with DOS style line endings (0x0d 0x0a) (of course, technically speaking this might be considered a bug!). But the other side of it is that i'd like to do this selectively, ensuring that what I'm fixing really is a...

How can I grep and sort text files using Perl?

I have a simple log file which is very messy and I need it to be neat. The file contains log headers, but they are all jumbled up together. Therefore I need to sort the log files according to the log headers. There are no static number of lines - that means that there is no fixed number of lines for the each header of the text file. And ...

use grep to return a list of files, given multiple keywords (like google returns a list of webpages)

I need to find ALL files that have multiple keywords anywhere in the file (not necessarily on the same line), given a starting directory like ~/. Does "grep -ro" do this? (I'm using Unix, Mac OSX 10.4) ...

Bash script process name regex

I'm trying to regex process id's based on parts of a process name. It seems to work if I only do a single word, but it fails when I try to do something like: find me any process with path /beginning ** /endswiththis/ Here's what I have so far: QUEUE_PID="$(ps -ef | grep endswiththis | grep -v $0 | grep -v grep | awk '{ print $2 }')"; ...

Find all files matching 'name' on linux system, and search with them for 'text'

Hi, I need to find all instances of 'filename.ext' on a linux system and see which ones contain the text 'lookingfor'. Is there a set of linux command line operations that would work? ...

Cucumber: pipe output without losing color

I'm using cucumber to run some tests. It colorizes its output using ANSI escapes. This is great, but currently its producing more output than I care about, and shoving things I do care about off the screen. There doesn't seem to be a way to eliminate the other lines from within cucumber, but I can pipe the output through grep to pare ...

Convert parts=path1,size1,...,lastPath,-1 :-> parts=nPath,nSize,lastPath,-1 ; all possible conditions (no path1,size1,... ; OR no lastPath,-1 )

i have following pattern parts=/a,1mb,/b/c,2gb,/zee/last,-1 #general form on next line ^parts=path1,size1,...,lastPath,-1$ I want to replace all $path1,$size1 except $lastplace,-1 with $newPath,$newSize i.e. parts_new=/p,2mb,/q/r,5gb,/zee/last,-1 #general on next line ^parts=newPathX,newSizeX,lastPath,-1$ I figured how to do it usi...

How can I grep a paragraph in Perl?

Hi there! I have a log file which needs to be properly formatted into a readable format. However the text file has no static number of lines or fixed primary values and has random number of spaces but has only a log file header which can be used to pin point the start and end of each time the application logs. An Example of the log file...

Extract Title of a html file using grep

cat 1.html | grep "<title>" > title.txt This wont work .. please tell the best way to grab the title of a page using grep or sed .. Thanks . ...

How can I implement Unix grep in Perl?

How can I implement grep of Unix in Perl? I tried to use Perl's built-in grep. Here is the code which is not working: $pattern = @ARGV[0]; $file= @ARGV[1]; open($fp,$file); @arr = <$fp>; @lines = grep $pattern, @arr; close($fp); print @lines; And by the way, i am trying only basic grep functionality not full featured and secondly ...

How do I get the output of an object which has more than one line in Perl?

@ver = $session->cmd("sh conf"); The variable here is ver, which has the configuration file, that is, it has more than one line. So how to take an output of each line of the ver variable without putting it in a loop? ...

Find a string in all the files on the system.

Hi all. Using PHP, how to find all the files in the whole system (I am using ubuntu) which contain string errorlog. I tried exec() and grep but it is taking just one occurrence. Thanks. ...

How to add a new column in a file

I have file like this which contains 5 columns. But some rows in my file have 4 columns by mistake, for example in this file at the 5th and 6th rows, you can see that the second column is missing. I want to replace the missing 2nd column with a blank space without disturbing other rows in my file with field separator ",". 11111,5323,62...