Re: which is the best command to use

2012-01-05 Thread weimen

于 2012-1-4 19:26, Wilko Fokken 写道:

On Tue, Dec 27, 2011 at 08:57:55PM +0800, lina wrote:

Hi,

I have two questions, wish to get advice,

Question 1:

For a series of files:

cat  a_*.o* | grep WARNING

some file like a_1.o12 has WARNING, but others does not have WARNING

How can I let grep returns the filename?


try grep -H
in order to get the filename.


Maybe you can try
$ grep -lR WARNING /pathname


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4f068bd4.70...@gmail.com



Re: which is the best command to use

2012-01-04 Thread Wilko Fokken
On Tue, Dec 27, 2011 at 08:57:55PM +0800, lina wrote:
 Hi,

 I have two questions, wish to get advice,

 Question 1:

 For a series of files:

 cat  a_*.o* | grep WARNING

 some file like a_1.o12 has WARNING, but others does not have WARNING

 How can I let grep returns the filename?


try grep -H
in order to get the filename.

-- 
Wilko FokkenEducation is a man's going
Landschaftspolder 67from cocksure ignorance
D-26831 Bunde   to thoughtful uncertainty.

Tel. 04953-9219882


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120104112626.gb8...@fok01.laje.edewe.de



Re: which is the best command to use

2011-12-27 Thread Bill Dennen
On Tue, 27 Dec 2011 14:20:02 +0100, lina scribbled:

 On Tuesday 27,December,2011 08:57 PM, lina wrote:
 Hi,

 I have two questions, wish to get advice,

 Question 1:

 For a series of files:

 cat  a_*.o* | grep WARNING

 some file like a_1.o12 has WARNING, but others does not have WARNING

 How can I let grep returns the filename?
 
 I wrote a very-low-level and not-work-as-expected one,
 
 #!/bin/sh
 
 for filename in *.o*
 
 do
 #echo $filename
 a= cat $filename | grep WARNING
  if [ a ]
  then
  echo $filename
  fi
 
 done
 
 Please give me some advice,
 
 Best regards,
 
 

 Question 2:

 ls . | xargs -i -t cp ./{} {}.bak

 How does xargs work,

 I checked google, :
 -i : replace the string
 -t print
 but still lack well understanding,

 how those xargs organise things,

 and
 $ ls .
 a.txt b.txt

 above will give a.txt.bak b.txt.bak
 ls | xargs -i cp ./{} {basename {}.bak} definitely not work,


 Sorry I send it to debian list, I asked on another bash list, for two
 days the second question, no one replied. I have much more faith in
 this list.

 WIth all the best regards,

From man grep ...
   -l, --files-with-matches
  Suppress normal output; instead print the name of each input
  file from which output would normally have been printed.  The
  scanning will stop on the first match.   (-l is specified by
  POSIX.)

so
$ grep -l *.o*
   or
$ grep --file-with-matches *.o*
should do what you want.


-- 
@
Bill Dennen ieee1...@hotmail.com
Of all the things I've lost, I miss my mind the most ...


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/jdciih$mq1$1...@speranza.aioe.org



Re: which is the best command to use

2011-12-27 Thread lina

On Tuesday 27,December,2011 08:57 PM, lina wrote:

Hi,

I have two questions, wish to get advice,

Question 1:

For a series of files:

cat  a_*.o* | grep WARNING

some file like a_1.o12 has WARNING, but others does not have WARNING

How can I let grep returns the filename?


I wrote a very-low-level and not-work-as-expected one,

#!/bin/sh

for filename in *.o*

do
#echo $filename
a= cat $filename | grep WARNING
if [ a ]
then
echo $filename
fi

done

Please give me some advice,

Best regards,




Question 2:

ls . | xargs -i -t cp ./{} {}.bak

How does xargs work,

I checked google, :
-i : replace the string
-t print
but still lack well understanding,

how those xargs organise things,

and
$ ls .
a.txt b.txt

above will give a.txt.bak b.txt.bak
ls | xargs -i cp ./{} {basename {}.bak}
definitely not work,


Sorry I send it to debian list, I asked on another bash list, for two 
days the second question, no one replied. I have much more faith in 
this list.


WIth all the best regards,



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4ef9c411.90...@gmail.com



Re: which is the best command to use

2011-12-27 Thread Bill Dennen
On Tue, 27 Dec 2011 14:20:02 +0100, lina scribbled:

 On Tuesday 27,December,2011 08:57 PM, lina wrote:
 Hi,

 I have two questions, wish to get advice,

 Question 1:

 For a series of files:

 cat  a_*.o* | grep WARNING

 some file like a_1.o12 has WARNING, but others does not have WARNING

 How can I let grep returns the filename?
 
 I wrote a very-low-level and not-work-as-expected one,
 
 #!/bin/sh
 
 for filename in *.o*
 
 do
 #echo $filename
 a= cat $filename | grep WARNING
  if [ a ]
  then
  echo $filename
  fi
 
 done
 
 Please give me some advice,
 
 Best regards,
 
 

 Question 2:

 ls . | xargs -i -t cp ./{} {}.bak

 How does xargs work,

 I checked google, :
 -i : replace the string
 -t print
 but still lack well understanding,

 how those xargs organise things,

 and
 $ ls .
 a.txt b.txt

 above will give a.txt.bak b.txt.bak
 ls | xargs -i cp ./{} {basename {}.bak} definitely not work,


 Sorry I send it to debian list, I asked on another bash list, for two
 days the second question, no one replied. I have much more faith in
 this list.

 WIth all the best regards,

whoops, my bad (so focused on the -l)
its
$ grep -l WARNING *.o*

:(



-- 
@
Bill Dennen ieee1...@hotmail.com
Of all the things I've lost, I miss my mind the most ...


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/jdcimp$mq1$2...@speranza.aioe.org



Re: which is the best command to use

2011-12-27 Thread lina

On Tuesday 27,December,2011 09:51 PM, Tony Baldwin wrote:

On Tue, Dec 27, 2011 at 09:11:45PM +0800, lina wrote:

On Tuesday 27,December,2011 08:57 PM, lina wrote:

Hi,

I have two questions, wish to get advice,

Question 1:

For a series of files:

cat  a_*.o* | grep WARNING

some file like a_1.o12 has WARNING, but others does not have WARNING

How can I let grep returns the filename?

I wrote a very-low-level and not-work-as-expected one,

#!/bin/sh

for filename in *.o*

do
#echo $filename
a= cat $filename | grep WARNING
 if [ a ]
 then
 echo $filename
 fi

done


for filename in *.o*; do
if [ grep WARNING ];
then echo $filename
fi
done


Thanks,
$ ./return_error_filename.sh
./return_error_filename.sh: line 6: [: grep: unary operator expected


$ cat return_error_filename.sh
#!/bin/sh

for filename in *.o*

do
if [ grep WARNING ];
then
echo $filename
fi

done


./tony




--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4ef9d1ce.2000...@gmail.com



Re: which is the best command to use

2011-12-27 Thread Raf Czlonka
On Tue, Dec 27, 2011 at 01:19:20PM GMT, Andrei Popescu wrote:
 To answer the question in your subject I think the correct command to 
 use is 'man' :)

Well put, sir! +1 ;^)

Regards,
-- 
Raf


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20111227140350.gb32...@linuxstuff.pl



Re: which is the best command to use

2011-12-27 Thread lina

On Tuesday 27,December,2011 09:19 PM, Andrei Popescu wrote:

On Ma, 27 dec 11, 20:57:55, lina wrote:

Hi,

I have two questions, wish to get advice,

Question 1:

For a series of files:

cat  a_*.o* | grep WARNING

Useless use of 'cat' (grep can open files)


some file like a_1.o12 has WARNING, but others does not have WARNING

How can I let grep returns the filename?

 From your explanation it's not clear to me if you want -l or -H, but you
might just read 'man grep' and decide for yourself ;)

Not familiar with xargs, but you should probably read that manpage too.

To answer the question in your subject I think the correct command to
use is 'man' :)

Kind regards,
Andrei

I didn't realize I could find answer from manuals of grep.

Thanks,


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4ef9c84d.1090...@gmail.com



Re: which is the best command to use

2011-12-27 Thread Raf Czlonka
On Tue, Dec 27, 2011 at 12:57:55PM GMT, lina wrote:
 Hi,
 
 I have two questions, wish to get advice,
 
 Question 1:
 
 For a series of files:
 
 cat  a_*.o* | grep WARNING

It's one of the useless uses of cat[0].

Use:

% grep WARNING a_*.o*

instead.

 some file like a_1.o12 has WARNING, but others does not have WARNING
 
 How can I let grep returns the filename?

% man grep

-l, --files-with-matches
Suppress normal output; instead print the name of each input file
from which output would normally have been printed. The scanning
will stop on the first match. (-l is specified by POSIX.)

 Question 2:
 
 ls . | xargs -i -t cp ./{} {}.bak
 
 How does xargs work,
 
 I checked google, :

Maybe it's time to start checking man instead ;^)

% man xargs

 -i : replace the string

--replace[=replace-str]
-i[replace-str]
This option is a synonym for -Ireplace-str if replace-str is
specified, and for -I{} otherwise.
This option is deprecated; use -I instead.

 -t print

--verbose
-t
Print the command line on the standard error output before
executing it.

 but still lack well understanding,

it's quite self explanatory ;^)

 how those xargs organise things,
 
 and
 $ ls .
 a.txt b.txt
 
 above will give a.txt.bak b.txt.bak
 ls | xargs -i cp ./{} {basename {}.bak}
 definitely not work,

How about:

% ls | xargs -I '{}' cp '{}' '{}'.bak

BTW, if you're only after copying the files with .bak appended to the
copied file name, this should suffice.

for i in `ls` ; do cp $i $i.bak ; done

There are other ways to do it as well.

 Sorry I send it to debian list, I asked on another bash list, for
 two days the second question, no one replied. I have much more faith
 in this list.

Good to hear that, but maybe you should start to reading more and
test a bit yourself before you write an email. It'll definitely be less
than two days to find a solution and sometimes it'll take less time to
find it in the manual than to write an email.

I appreciate the fact that you're a beginner but your problems are
NOT Debian-specific and ARE trivial to resolve so maybe it's time
to learn how to look for solutions yourself rather than others holding
your hand all the time, eh? ;^)

[0] http://partmaps.org/era/unix/award.html

All the best.
-- 
Raf


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/2011122714.ga32...@linuxstuff.pl



Re: which is the best command to use

2011-12-27 Thread Andrei Popescu
On Ma, 27 dec 11, 20:57:55, lina wrote:
 Hi,
 
 I have two questions, wish to get advice,
 
 Question 1:
 
 For a series of files:
 
 cat  a_*.o* | grep WARNING

Useless use of 'cat' (grep can open files)
 
 some file like a_1.o12 has WARNING, but others does not have WARNING
 
 How can I let grep returns the filename?

From your explanation it's not clear to me if you want -l or -H, but you 
might just read 'man grep' and decide for yourself ;)

Not familiar with xargs, but you should probably read that manpage too.

To answer the question in your subject I think the correct command to 
use is 'man' :)

Kind regards,
Andrei
-- 
Offtopic discussions among Debian users and developers:
http://lists.alioth.debian.org/mailman/listinfo/d-community-offtopic


signature.asc
Description: Digital signature


which is the best command to use

2011-12-27 Thread lina

Hi,

I have two questions, wish to get advice,

Question 1:

For a series of files:

cat  a_*.o* | grep WARNING

some file like a_1.o12 has WARNING, but others does not have WARNING

How can I let grep returns the filename?


Question 2:

ls . | xargs -i -t cp ./{} {}.bak

How does xargs work,

I checked google, :
-i : replace the string
-t print
but still lack well understanding,

how those xargs organise things,

and
$ ls .
a.txt b.txt

above will give a.txt.bak b.txt.bak
ls | xargs -i cp ./{} {basename {}.bak}
definitely not work,


Sorry I send it to debian list, I asked on another bash list, for two 
days the second question, no one replied. I have much more faith in this 
list.


WIth all the best regards,


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4ef9c0d3@gmail.com



Re: which is the best command to use

2011-12-27 Thread Tony Baldwin
On Tue, Dec 27, 2011 at 09:11:45PM +0800, lina wrote:
 On Tuesday 27,December,2011 08:57 PM, lina wrote:
 Hi,
 
 I have two questions, wish to get advice,
 
 Question 1:
 
 For a series of files:
 
 cat  a_*.o* | grep WARNING
 
 some file like a_1.o12 has WARNING, but others does not have WARNING
 
 How can I let grep returns the filename?
 
 I wrote a very-low-level and not-work-as-expected one,
 
 #!/bin/sh
 
 for filename in *.o*
 
 do
 #echo $filename
 a= cat $filename | grep WARNING
 if [ a ]
 then
 echo $filename
 fi
 
 done
 

for filename in *.o*; do
if [ grep WARNING ]; 
then echo $filename
fi
done

./tony

-- 
http://www.tonybaldwin.net
All Tony, all the time!


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/20111227135124.ga26...@deathstar.hsd1.ct.comcast.net



RE: which is the best command to use

2011-12-23 Thread Arno Schuring

 
 well, I have two files:
 
 File_a.txt
 a
 a
 a
 
 File_b.txt
 b
 b
 b
 
 I wish to get a file_ab.txt as
 a b
 a b
 a b
 

man 1 paste   Regards,Arno

Re: which is the best command to use

2011-12-23 Thread Roman Khomasuridze
You can use paste, and/or join. for you particular example
paste -d ' ' a.txt b.txt  ab.txt
will work

Regards
--
Roman


On Fri, Dec 23, 2011 at 12:07 PM, Arno Schuring aelschur...@hotmail.comwrote:

  
  well, I have two files:
 
  File_a.txt
  a
  a
  a
 
  File_b.txt
  b
  b
  b
 
  I wish to get a file_ab.txt as
  a b
  a b
  a b
 

 man 1 paste


 Regards,
 Arno




Re: which is the best command to use

2011-12-23 Thread lina
On Fri, Dec 23, 2011 at 4:13 PM, Roman Khomasuridze
khomasuri...@gmail.com wrote:
 You can use paste, and/or join. for you particular example
 paste -d ' ' a.txt b.txt  ab.txt
 will work

Thanks cool. a derived question,

for a.txt:
1 a
2 a
3 a

for b.txt
1 b
2 b
3 b

what if I only interested the 2 filed.

namely
a b
a b
a b

I tried use paste -d ' ' a.txt b.txt | awk 'print $2, $4'
are there some other way of doing it?

No doubt it's a very smart list, I wasted 1 hour writing some not
sound python script, it's a bunch of files anyway.

Thanks again,

 Regards
 --
 Roman



 On Fri, Dec 23, 2011 at 12:07 PM, Arno Schuring aelschur...@hotmail.com
 wrote:

 
  well, I have two files:
 
  File_a.txt
  a
  a
  a
 
  File_b.txt
  b
  b
  b
 
  I wish to get a file_ab.txt as
  a b
  a b
  a b
 

 man 1 paste


 Regards,
 Arno





-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/CAG9cJmmgssfdcPJqtMD+uBzf0hUff+j+EtTcg2b203DEj=o...@mail.gmail.com



Re: which is the best command to use

2011-12-23 Thread André Berger
* lina (2011-12-23):
[...]
 File_a.txt
 a
 a
 a
 
 File_b.txt
 b
 b
 b
 
 I wish to get a file_ab.txt as
 a b
 a b
 a b

apt-get install coreutils
paste File_a.txt File_b.txt

-André

-- 
L'art d'ennuyer est de tout dire. [Voltaire]


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20111223081216.ga87...@albedo.lan



Re: which is the best command to use

2011-12-23 Thread Chris Davies
lina lina.lastn...@gmail.com wrote:
 Thanks cool. a derived question,

 for a.txt:
 1 a
 2 a
 3 a

 for b.txt
 1 b
 2 b
 3 b

 what if I only interested the 2 filed.

 namely
 a b
 a b
 a b

Are the 1, 2, 3 relevant? So if you had this, what would you expect as
your output -

a.txt
1 a
2 b
3 c

b.txt
1 d
2 e
3 f


 I tried use paste -d ' ' a.txt b.txt | awk 'print $2, $4'
 are there some other way of doing it?

That's good if the numeric column is irrelevant. You could use cut
instead of awk, but it gets you much the same result. (You could replace
the paste and the awk with a single instance of perl, but frankly I
wouldn't make the effort for this kind of situation.)

Chris


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/ah2es8x6sr@news.roaima.co.uk



which is the best command to use

2011-12-22 Thread lina
Hi,

(How are you all?)

well, I have two files:

File_a.txt
a
a
a

File_b.txt
b
b
b

I wish to get a file_ab.txt as
a b
a b
a b

I tried, but still don't know which is the best way to do it,

Thanks ahead and wish all have a nice holiday,

Best regards,


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/CAG9cJmmcJsfXQrhcRZugB27G=uz9rhhrhjajey-fc3fmku2...@mail.gmail.com