How to use grep

How to use grep

am 16.01.2008 06:22:07 von harishashim

Hello !

Let say I have a text file with the following line


L1 ABCD
L2 EFGH
L3 IJKLM
L4 NOPQ
L5 RST

I want to grep line 1 and line 4 so that the output of grep operation
is

L1 ABCD
L4 NOPQ

What is the grep command then?

Thanks in advance!

Re: How to use grep

am 16.01.2008 06:44:28 von mik3l3374

On Jan 16, 1:22 pm, harishas...@gmail.com wrote:
> Hello !
>
> Let say I have a text file with the following line
>
> L1 ABCD
> L2 EFGH
> L3 IJKLM
> L4 NOPQ
> L5 RST
>
> I want to grep line 1 and line 4 so that the output of grep operation
> is
>
> L1 ABCD
> L4 NOPQ
>
> What is the grep command then?
>
> Thanks in advance!

does it actually have the word L1 , L2 etc as the first 2 characters.
If that's a yes, then this is one way

# egrep "^(L1|L4)" file

else ifs it just line number 1 and 4,

# sed -n '1p;4p' file

Re: How to use grep

am 16.01.2008 07:02:08 von cfajohnson

On 2008-01-16, harishashim@gmail.com wrote:
>
>
> Hello !
>
> Let say I have a text file with the following line
>
>
> L1 ABCD
> L2 EFGH
> L3 IJKLM
> L4 NOPQ
> L5 RST
>
> I want to grep line 1 and line 4 so that the output of grep operation
> is
>
> L1 ABCD
> L4 NOPQ
>
> What is the grep command then?

What are you looking for?

If you want the first and fourth lines:

sed -n -e 1p -e 4p FILE

If you want to search for ABCD and NOPQ:

grep -e ABCD -e NOPQ FILE

--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence

Re: How to use grep

am 16.01.2008 08:34:48 von redraiment

Maybe can use command:
grep -E 'A|N' [filename]