How to use grep

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!
harishashim [ Mi, 16 Januar 2008 06:22 ] [ ID #1908920 ]

Re: How to use grep

On Jan 16, 1:22 pm, harishas... [at] 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
mik3l3374 [ Mi, 16 Januar 2008 06:44 ] [ ID #1908921 ]

Re: How to use grep

On 2008-01-16, harishashim [at] 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 <http://cfaj.freeshell.org/shell/>
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
cfajohnson [ Mi, 16 Januar 2008 07:02 ] [ ID #1908922 ]

Re: How to use grep

Maybe can use command:
grep -E 'A|N' [filename]
redraiment [ Mi, 16 Januar 2008 08:34 ] [ ID #1908923 ]
Linux » comp.unix.shell » How to use grep

Vorheriges Thema: Redirection
Nächstes Thema: [tcsh] $argv loses quotes, messes argument grouping up