From: nag on 6 Jun 2010 10:00 Hi all! I want to know how to grep a particular string from a latest file output.... example.... i have a list files like file1 file2 file3 acutally the files are having a similar name with date and time stamp. Here i am listing them with ls command and taking the latest file with tail -1 command. I want to grep a string say McHill from the latest file, say file3. Here is my code... ls | tail -1 > x1 var=`cut -c1-4` grep McHill $var > output which is giving error. even I tried.... ls | tail -1 | grep McHill > output which is not giving any output... If not shell solution....is there any awk solution? please...
From: Janis Papanagnou on 6 Jun 2010 10:11 nag wrote: > Hi all! > > I want to know how to grep a particular string from a latest file > output.... > > example.... > > i have a list files like > > file1 > file2 > file3 > > acutally the files are having a similar name with date and time stamp. > Here i am listing them with ls command and taking the latest file with > tail -1 command. I want to grep a string say McHill from the latest > file, say file3. Here is my code... > > ls | tail -1 > x1 > > var=`cut -c1-4` > grep McHill $var > output > > which is giving error. > > even I tried.... > > ls | tail -1 | grep McHill > output > > which is not giving any output... > > If not shell solution....is there any awk solution? please... > > > Your posting is not very clear, especially where you've been using cut(1). Please explain and provide samples of actual data if you want some more magic implemented that we could just guess. To grep in the lexicographically "latest" file (which is what you're doing above, and which seems to be possible due to a sensible date format that you may be using), here's one way : file* grep McHill "$_" > output In the first line you can define the file globbing pattern after the colon. Janis
From: nag on 6 Jun 2010 10:40 On Jun 6, 7:11 pm, Janis Papanagnou <janis_papanag...(a)hotmail.com> wrote: > nag wrote: > > Hi all! > > > I want to know how to grep a particular string from a latest file > > output.... > > > example.... > > > i have a list files like > > > file1 > > file2 > > file3 > > > acutally the files are having a similar name with date and time stamp. > > Here i am listing them with ls command and taking the latest file with > > tail -1 command. I want to grep a string say McHill from the latest > > file, say file3. Here is my code... > > > ls | tail -1 > x1 > > > var=`cut -c1-4` > > grep McHill $var > output > > > which is giving error. > > > even I tried.... > > > ls | tail -1 | grep McHill > output > > > which is not giving any output... > > > If not shell solution....is there any awk solution? please... > > Your posting is not very clear, especially where you've been using cut(1).. > Please explain and provide samples of actual data if you want some more > magic implemented that we could just guess. > > To grep in the lexicographically "latest" file (which is what you're doing > above, and which seems to be possible due to a sensible date format that > you may be using), here's one way > > : file* > grep McHill "$_" > output > > In the first line you can define the file globbing pattern after the colon. > > Janis- Hide quoted text - > > - Show quoted text - sorry i mad a mistake in the post...the correctioin.... > > ls | tail -1 > x1 > ......... var=`cut -c1-4 x1` grep McHill $var > output Where i am doing mistake? my files are lke this.. SCH<date>.<timestamp> i want to grep from the latest time stamped file.
From: Ben Bacarisse on 6 Jun 2010 10:56 nag <visitnag(a)gmail.com> writes: <snip> > sorry i mad a mistake in the post...the correctioin.... > >> > ls | tail -1 > x1 >> > ........ var=`cut -c1-4 x1` > > grep McHill $var > output > > Where i am doing mistake? The cut. As far as I can see its only purpose is to make var into a string that is not the name of one of your files. What did you think it was doing to help? > my files are lke this.. > > SCH<date>.<timestamp> [The cut -c1-4 means that var will get "SCH" and the first letter of the date. That's not going to be a file name so you won't be able to grep it.] > i want to grep from the latest time stamped file. grep McHill "$(ls SCH* | tail -1)" >output seems to be much closer to what you want. BTW, if you get an error, you should post it. I image you were getting something like: "grep: CSHx: No such file or directory". -- Ben.
From: Allodoxaphobia on 6 Jun 2010 16:11 On Sun, 6 Jun 2010 07:00:53 -0700 (PDT), nag wrote: > Hi all! > > I want to know how to grep a particular string from a latest file > output.... > > example.... > > i have a list files like > > file1 > file2 > file3 > > acutally the files are having a similar name with date and time stamp. > Here i am listing them with ls command and taking the latest file with > tail -1 command. I want to grep a string say McHill from the latest > file, say file3. Here is my code... $ grep McHill $(ls -tr | tail -n 1) -or- $ grep McHill $(ls -tr file* | tail -n 1) Jonesy -- Marvin L Jones | jonz | W3DHJ | linux 38.24N 104.55W | @ config.com | Jonesy | OS/2 * Killfiling google & XXXXbanter.com: jonz.net/ng.htm
|
Pages: 1 Prev: Join Lines Next: [Meta] for the record - please ignore (was Re: how to transpose largematrix?) |