Unix Programming - How to fix a 'grep' command from LINUX to UNIX?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2004 > How to fix a 'grep' command from LINUX to UNIX?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to fix a 'grep' command from LINUX to UNIX?
Nuage

2004-01-28, 6:39 am

Hello,

I am having a problem. Could someone help me?

The following command works in LINUX:

tail +2 | grep -iv [a-z] /home/usr/...../filefgd.asc > /home/usr/...../tmp.asc

It does not work in UNIX:

it says:
grep: no match
only the tail +2 command works

Would you know an equivalent of this code that can be used in UNIX?

explanation of command:
tail +2 /start on line 2
| / and
grep -iv [a-z] /-i is for ignores lower case or upper case
/-v is for print all lins not containing the pattern
/[a-z] is the pattern, any alphabetic characters

Thank you

Nuage
=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=

2004-01-28, 6:39 am

khaluaa7@yahoo.com (Nuage) writes:
quote:

> Hello,
>
> I am having a problem. Could someone help me?
>
> The following command works in LINUX:
>
> tail +2 | grep -iv [a-z] /home/usr/...../filefgd.asc



Quote the pattern, like this '[a-z]'. You are using bash on the Linux
machine and tcsh on the other one. Bash will leave unmatched shell
globs alone, whereas tcsh complains.

--
Måns Rullgård
mru@kth.se
David Schwartz

2004-01-28, 7:36 am


"Nuage" <khaluaa7@yahoo.com> wrote in message
news:94719fdd.0401281156.6b931955@posting.google.com...

quote:

> The following command works in LINUX:
>
> tail +2 | grep -iv [a-z] /home/usr/...../filefgd.asc >
> /home/usr/...../tmp.asc
>
> It does not work in UNIX:
>
> it says:
> grep: no match
> only the tail +2 command works
>
> Would you know an equivalent of this code that can be used in UNIX?
>
> explanation of command:
> tail +2 /start on line 2
> | / and
> grep -iv [a-z] /-i is for ignores lower case or upper case
> /-v is for print all lins not containing the pattern
> /[a-z] is the pattern, any alphabetic characters




Maybe I'm being dense, but what is 'grep' supposed to be searching
through? The output of 'tail +2'? Or the contents of 'filefgd.asc'?

DS




Nuage

2004-01-28, 3:35 pm

Hello Mans,

How are you?
Thank you for your help.

'[a-z]' didn't work but "[a-z]" worked with grep.
However for some reason it would not execute the grep command right
after the tail command on the file.

tail +2 | grep -iv [a-z] /home/usr/filefg.asc > tmp.dat

I have tried:
unix([' tail +2 | grep -iv "[a-z]" /home/usr/filefg.asc > tmp.asc ']);

I have a data file which is composed of lines with alphabetic
characters and lines with numbers.

I wanted to remove the 1st line of the file so I used "tail +2" to
start it at the 2nd file. I have tried also "sed '1d'" which deletes
the 1st line.

I wanted the file to start at the 2nd line.

And right after it I wanted to remove all the lines of the file which
contains alphabetic characters, so only lines which have numbers would
be saved.

Here is how the file looks like

1 1 200 150
MOSAIC 2001070223 2001070300 COLS/ROWS: 10 50
ROW= 1
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
ROW= 2
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
ROW= 3
0 0 0 0 25 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
75 75 338 325 100 13 13 0 0 0 0
0 0 0 0 0 0 0 0 0 50 0
Nuage

2004-01-28, 3:35 pm

Hello David,

How are you?

Here is what I am trying to do:

'[a-z]' didn't work but "[a-z]" worked with grep.
However for some reason it would not execute the grep command right
after the tail command on the file.

tail +2 | grep -iv [a-z] /home/usr/filefg.asc > tmp.dat

I have tried:
unix([' tail +2 | grep -iv "[a-z]" /home/usr/filefg.asc > tmp.asc ']);

I have a data file which is composed of lines with alphabetic
characters and lines with numbers.

I wanted to remove the 1st line of the file so I used "tail +2" to
start it at the 2nd file. I have tried also "sed '1d'" which deletes
the 1st line.

I wanted the file to start at the 2nd line.

Then I wanted to remove all the lines of the file which contains
alphabetic characters, so only lines which have numbers would be
saved.

Here is how the file looks like, before and then after the change:

1 1 200 150
MOSAIC 2001070223 2001070300 COLS/ROWS: 10 50
ROW= 1
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
ROW= 2
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
ROW= 3
0 0 0 0 25 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
75 75 338 325 100 13 13 0 0 0 0
0 0 0 0 0 0 0 0 0 50 0



After the transformation:

0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 25 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
75 75 338 325 100 13 13 0 0 0 0
0 0 0 0 0 0 0 0 0 50 0
William Park

2004-01-28, 3:35 pm

Nuage <khaluaa7@yahoo.com> wrote:
quote:

> Hello,
>
> I am having a problem. Could someone help me?
>
> The following command works in LINUX:
>
> tail +2 | grep -iv [a-z] /home/usr/...../filefgd.asc > /home/usr/...../tmp.asc
>
> It does not work in UNIX:



Nonsense. Both will work. By the way, get rid of 'tail' command.

--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution for data management and processing.
Chris F.A. Johnson

2004-01-28, 3:35 pm

On Thu, 29 Jan 2004 at 04:39 GMT, William Park wrote:
quote:

> Nuage <khaluaa7@yahoo.com> wrote:
>
> Nonsense. Both will work. By the way, get rid of 'tail' command.



But then he'll get the first line, which he doesn't want.

He could also do:

{
read
grep -iv "[a-z]" ## single quotes also work
} < /home/usr/...../filefgd.asc > /home/usr/...../tmp.asc


--
Chris F.A. Johnson http://cfaj.freeshell.org
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Floyd Davidson

2004-01-28, 4:34 pm

"Chris F.A. Johnson" <c.fa.johnson@rogers.com> wrote:
quote:

>William Park wrote:
>
> But then he'll get the first line, which he doesn't want.
>
> He could also do:
>
>{
> read
> grep -iv "[a-z]" ## single quotes also work
>} < /home/usr/...../filefgd.asc > /home/usr/...../tmp.asc



He could keep the tail command too,

tail +2 /home/usr/...../filefgd.asc | grep -iv '[a-z]' > /home/usr/...../tmp.asc


--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@barrow.com
Barry Margolin

2004-01-28, 4:34 pm

In article <bva348$pmagv$3@ID-210011.news.uni-berlin.de>,
"Chris F.A. Johnson" <c.fa.johnson@rogers.com> wrote:
quote:

> On Thu, 29 Jan 2004 at 04:39 GMT, William Park wrote:
>
> But then he'll get the first line, which he doesn't want.



The first line of what? He didn't give any filenames to the tail
command, so it's going to read from stdin (the terminal if he's entering
these commands interactively). And he *is* giving a filename argument
to grep, so it's going to read that file rather than the output of tail.

Maybe what he meant was:

tail +2 /home/usr/.../filefgd.asc | grep -iv '[a-z]' >
/home/usr/.../tmp.asc

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Nuage

2004-01-29, 10:34 am

Dear Barry,

Thank you very much for help.

I appreciate it very much. Now the command is working properly.


Nuage
Nuage

2004-01-29, 10:34 am

Dear Floyd,

Thank you for your help.

I appreciate it very much. Now the command is working properly.


Nuage
Nuage

2004-01-29, 10:34 am

Hello Chris,

Thank you very much for your help. I tried both " . " ' . ', only
wiuth double quotes it worked.

Nuage
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com