Programming :: Use Grep To Fetch Lines Contain 'AB_001'

Sep 17, 2010

I have such a file(test.txt) as below:

[code]...

I want to use grep to fetch the lines contain 'AB_001'.

[code]...

get the first 2 lines, not the 'AB_0011/10/105'.

View 2 Replies


ADVERTISEMENT

Programming :: Displaying Particular Lines Via Grep ?

Apr 8, 2011

So For example I run this command:

Code:

But want to gerp / cut it in such a way that it only displays

Code:

Now the thing is that these 3 lines are not static.. there can be N number of lines there.. the only thing is that I want the command / output NOT to display the first line but the rest of the n lines ..

View 9 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 :: Get Rid Of Unwanted Lines Without Grep -v In BASH?

Jun 9, 2009

I would like to know how I can get the ouput from the following dmidecode command in example 1 to look like example 2 without having to grep -v all the unwanted lines.Is there a way in awk or sed?Example 1

Code:
Processor Information
Socket Designation: Socket 1 CPU 1

[code]...

View 7 Replies View Related

General :: Finding Surrounding Lines With Grep?

Aug 7, 2010

I know how to use grep to output a line that matches a string. But what if I also want to output one line above every line containing a matching string, how do I do that?

View 1 Replies View Related

General :: Grep - A-Z - Returns Unmatched Lines ?

Feb 21, 2011

Does anyone know why something like:

echo lowercase | grep [A-Z]

Would still return the lowercase line even tho there is no match?

Using --color will show there is no match but the line is still returned.

I am still new but from what i've learned this should not work like that. ubuntu 10.10

View 13 Replies View Related

General :: Grep And Store Two Lines In Other File

Feb 16, 2011

I have following contents

I want to grep "#2" and want the output as

How to using shell script?

View 6 Replies View Related

General :: Grep To Select Lines With M In Last Word

Mar 6, 2011

I have a large file in which each line has three or more blank-delimited words. I'd like to code a grep to keep only those lines which have the letter M in the last word. the M (if present) will be the first character in the last word.

View 14 Replies View Related

General :: Grep Varying No. Of Lines Between Two Patterns

Apr 11, 2011

I have a file that goes like this:

I need to grep the lines between pattern 1 and pattern 2 and not the lines following pattern 2. Cannot use grep -A(num), as there are varying number of lines following pattern 1. Also, used awk one-liners, but results are erroneous.

View 14 Replies View Related

General :: Use Grep To Match Multiple Lines?

Feb 3, 2011

I have done this before but i cant really recall now

I have a text file and i want to grep the word "interface" and 10 lines following it. I think there was some switch like grep -A or something ?

View 2 Replies View Related

General :: Grep Multiple Lines From A Text File

Jun 17, 2009

I have a list of words that I want to grep in many files to see which ones have it and which ones dont. in the text file I have all the words listed line by line, ex: list.txt:

check
try this
word1
word2
open space
list ..

I want to grep each line one by one. like I want it to

grep "check" *.log
grep "try this" *.log
grep "word1" *.log .. etc how can I do this?

and maybe write the output to a file.

View 5 Replies View Related

Programming :: Input File - Grep Within Grep

Nov 22, 2010

I need to kind of grep within grep. My input file would be something like:

[Code]....

and I need to find the first occurrence of hello before MY PATTERN (hello 9008 in this case), so the output should be:

[Code]....

View 4 Replies View Related

General :: Filtering Out Duplicate Lines From A Find/grep Output

Mar 22, 2010

I have some big files of logs that contain errors printed by an app. They are most of the time relevant, however most of them are similar. So i figured i could check what happened between a time interval with a find.

Im using this one

Code:

And I get an output similar to this one.

Code:

Is there a way to condensate the output lines to get only one or two, indicating the start and last occurrence of a block? Or I need to create a program to do so?

Because right now I get thousands of similar lines, but when I'm scrolling through them i sometimes miss relevant information that i would've otherwise noted if it wasn't all that spammy.

View 10 Replies View Related

Programming :: Remove Lines And Parts Of Lines From Python Strings?

Nov 24, 2009

How do you remove parts of strings using python? Such as, if I have something like:

Code:
erme1 sdifskenklsd
erme2 sdfjksliel

[code]....

View 3 Replies View Related

General :: Grep Lines Containing A Certain String PLUS The Line Following That Line?

Sep 1, 2009

I have a dataset (see example below) that I would like to go through and copy all lines containing a certain string ("LGIG") plus the line immediately following that line to a new file. I have no problem grepping lines containing the string LGIG but I'm lost how to translate that to line number and shift up one line number for each instance of that string.

Example input file:

[code].....

View 5 Replies View Related

Programming :: Bash Script Which Uses Awk To To Fetch A Line From A File?

Mar 24, 2010

Below is the part of my bash script which uses awk to to fetch a line from a file. Choice is set by a case, and i know it is receiving a proper number because of the echo statement. The problem is with the syntax of the awk command it says the error is with one of the ', but when I run the command at the command line and replace "$choice" with a number it works properly. So I am not sure what is going on.

echo "announcing choice $choice"
command="awk 'NR = "$choice"' beerpong.txt | say"
$command

View 8 Replies View Related

Programming :: Fetch The Remote Client Mac Address On Socket Descriptor?

Dec 14, 2010

I have written one simple code which is posted here. i want to fetch the Mac Address on socket descriptor which is returned after accept () call.

Code:-

#include<stdio.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>

[code].....

View 1 Replies View Related

Debian :: Error - Fetch Failed: W:Failed To Fetch Bzip2:/var/lib/apt/lists/partial

Feb 13, 2011

Lately when I've tried to update my packages many of them don't update. I get nothing out of the ordinary when using the terminal but when I try to update via the Update manger I get this error message:

Code:
Error message:
Fetch failed: W:Failed to fetch bzip2:/var/lib/apt/lists/partial/mirror.steadfast.net_debian_dists_testing_main_source_Sources Hash Sum mismatch
W:Failed to fetch bzip2:/var/lib/apt/lists/partial/mirror.steadfast.net_debian_dists_testing_main_binary-amd64_Packages Hash Sum mismatch, W:Failed to fetch http://mirror.steadfast.net/debian/dists/testing/updates/main/source/Sources 404 Not Found [IP: 208.100.4.53 80]

[Code]...

I've tried several different mirrors but get the same error with every one. Same result with ftp as well. Yesterday I upgraded to Wheezy and every package successfully upgraded, but today the problem started again.

View 10 Replies View Related

Programming :: Grep Not Getting Whole String?

Aug 23, 2010

I am trying to monitor how long an ldap search takes and maybe notify or something that a search takes longer than say 10 seconds.

Code:
tail -n 1000 /var/log/ldap.log
for SRCH in $( cat monitorldap.log |grep 'SRCH'); do
echo search string is
echo $SRCH

[Code]....

ok, so to start off with it doesn't appear to get the whole line, just a piece "Aug". How can I get the whole line into a variable so I can then cut it up into the pieces I need?

View 4 Replies View Related

Programming :: Grep -oE Not Portable?

Dec 28, 2010

I'm using Zabbix on which I can use give bash command to the agent.This 1-liner will give me all the interfaces with their IPv4 addresses.I have a 2nd expression which returns a checksum so I can detect a difference whenever someone deletes/adds/changes an ipv4 interface.This is the output on my Ubuntu-server:

Code:
~# ifconfig | grep -B1 ' inet ' | grep -oE '(^[a-z0-9:]*|addr:[0-9]+.[0-9]+.[0-9]+.[0-9]+)'
eth0

[code]....

View 8 Replies View Related

Programming :: Grep Search Between N-m

Oct 5, 2010

How can i use grep (or any other command) to check for lines that begin with N number.

E.g. I want to print out commands (from history), but only from the command number 50 until #200.

This one doesn't work:

Code:
history | grep "^[50-200]"
Should print out something like:
Code:
50 cd ~/Desktop

[Code].....

View 4 Replies View Related

Programming :: Grep For Exact Number 0?

Aug 6, 2010

1) I need to search a field value to check for exact 0. If the number is 0, it should throw error.

The line to be searched looks like as below. "Output Rows [1], Affected Rows [1], Applied Rows [1], Rejected Rows [0]"

Here I have to search whether the affected rows is 0. But the code below picks up other values also (lie 10, 20.. etc). How do we write to get an exact match for 0? Code: affected=`echo ${line} | cut -f6 -d" " `

affectedcount='echo ${affected} |grep 0 ` 2) Also, I need to check whether the rejected rows > 0
Code: rejected=`echo ${line} | cut -f12 -d" " `
rejectedcount='echo {rejected} |grep [1-9]`

3)Can we combine these two statements in a better way to get the desired results?

View 2 Replies View Related

Programming :: Tell If Grep Didn't Return Anything?

Mar 15, 2011

I have a file:

979798707
787862348
766428634

I want to see if all the records in the file are present in the contents of the files of a particular directory.

Basically I want to say if grep doesn't return anything, then report.

For example in /tmp dir I have 4 files and flast 2 values (787862348 and 766428634) are present in the files of /tmp dir, but first one (979798707) is not. I want to echo that in a reporting file.

something like:

while read line
do
# if ! grep -rl $line /tmp
echo $line >> are_not_present
done < "myFile"

How do I achieve " if ! grep -rl $line /tmp"? That is, if the line is found by grep, then grep will print the output, but if grep does'nt find it, it will print nothing. How can I check if grep didn't find it (i.e. printed nothing)?

View 2 Replies View Related

Programming :: Alternative For Code: Wc -l Using Grep?

Mar 23, 2011

Can you find an alternative for Code: wc -l using grep?

View 1 Replies View Related

Programming :: Program To Use Grep W/regex?

Jun 1, 2011

I'm just starting out with bash scripting (yesterday, really). I want to add a file to each user's home directory, pretty simple really, and send it out via our Apple Remote Desktop system to our Macs. Here is my script: Code: #!/bin/bash

for i in $(ls -d /Users/*)
doif [ -e $i/.tcshrc ]
thenecho "$i/.tcshrc exists!"elseecho "$i/.tcshrc does not exist"

[code]....

View 6 Replies View Related

Programming :: Bash: Using Grep To Filter 25 Or Above?

Dec 3, 2010

i have a sample that looks like this:

Code:
[schneidz@hyper temp]$ wget -q --output-document=- http://world.needforspeed.com/SpeedAPI/ws/game/nfs-w/leaderboards/events

[code]....

View 2 Replies View Related

Programming :: Grep A String With Space?

Feb 9, 2010

I am using Sun 5.9.

I am putting the value "Feb 10" in variable 'c' here.

Code:
-bash-3.00$ c=`date | awk '{print $2 " " $3}'`
-bash-3.00$ echo $c
Feb 10

But when I am grep-ing value of 'c', I am getting this error.

Code:
-bash-3.00$ ls -lrth | grep $c
grep: can't open 10

This is because there is a space between "Feb" and "10".

View 5 Replies View Related

Programming :: Grep Multiple Files ?

Dec 30, 2010

I want grep multiple files:

let abc.1.abc.2,abc.3,abc.4

I use grep <pattern> abc.* to read the files. But here grep read files in the order of 1,2,3,4 . I want to to grep the files in reverse order like 1st the abc.4 file will be read and abc.1 file will be last.

Is this possible ?

View 3 Replies View Related

Programming :: Grep The Patterns From The File?

Aug 10, 2010

I am interested in using the grep method in the shell of my CentOS machine to obtain patterns from a file and use them to search through another file and highlight the patterns found. For example:

pattern file:

one
two
three

test file:

AAAAAAAAAAAAAAAAAAAAAoneAAAAAAAAAAAAAAAAthreeAAAAAAAAAAAA

View 8 Replies View Related

Programming :: How To Get Grep Output 0 - 1 And Test It

Apr 7, 2009

I am trying to use a shell script to find a string in a file and do something when found. code...

What should happen is pppd will start in a different process and stream it's output to pppdout. pppdout should be created in the current folder. Then the script should periodically check the pppdout file for the string Script (which eventually will appear, some seconds later) and when found exit the script. Ultimately the script will do something useful when the text is found. However, the output from the program is a repeating: 'scriptname.sh: 12: FOUND: not found'

Where scriptname.sh would be the name of your script and 12 refers to the line with 'done'.

Why does grep not find the text, or at least why deos my script not check the grep output correctly?

View 10 Replies View Related







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