|
Home > Archive > Unix Shell > February 2007 > Unix Sort?
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]
|
|
| amerar@iwc.net 2007-02-21, 7:16 pm |
| Hi,
I have a file and I want to extract all the lines that start with a
number or letter, then sort those results, eliminating duplicates, and
place them in an output file.
I seem to have all the right parts, but cannot get them to work
together:
cat input.txt | grep '^[0-9][a-z][A-Z]' | sort -u > output.txt
Any help?
Thanks!
| |
| Stephane CHAZELAS 2007-02-21, 7:16 pm |
| 2007-02-21, 11:26(-08), amerar@iwc.net:
> Hi,
>
> I have a file and I want to extract all the lines that start with a
> number or letter, then sort those results, eliminating duplicates, and
> place them in an output file.
>
> I seem to have all the right parts, but cannot get them to work
> together:
>
> cat input.txt | grep '^[0-9][a-z][A-Z]' | sort -u > output.txt
grep '^[[:alnum:]]' < input.txt | sort -u > output.txt
--
Stéphane
| |
| Chris F.A. Johnson 2007-02-21, 7:16 pm |
| On 2007-02-21, amerar@iwc.net wrote:
> Hi,
>
> I have a file and I want to extract all the lines that start with a
> number or letter, then sort those results, eliminating duplicates, and
> place them in an output file.
>
> I seem to have all the right parts, but cannot get them to work
> together:
>
> cat input.txt | grep '^[0-9][a-z][A-Z]' | sort -u > output.txt
grep '^[0-9a-zA-Z]' input.txt | sort -u > output.txt
--
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
| |
| amerar@iwc.net 2007-02-21, 7:16 pm |
| On Feb 21, 1:29 pm, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2007-02-21, 11:26(-08), ame...@iwc.net:
>
>
>
>
>
> grep '^[[:alnum:]]' < input.txt | sort -u > output.txt
>
> --
> St=E9phane
Thanks for the tip, but that is not working......
| |
| Stephane CHAZELAS 2007-02-21, 7:16 pm |
| 2007-02-21, 11:40(-08), amerar@iwc.net:
[...]
[...][vbcol=seagreen]
> Thanks for the tip, but that is not working......
Please define "not working".
The command line above answers the question as you asked it as
long as you're using a standard grep and a standard sort on a
Unix (or even POSIX) system.
--
Stéphane
| |
| rengith.jerome@gmail.com 2007-02-22, 1:18 pm |
| On Feb 22, 12:26 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
> Hi,
>
> I have a file and I want to extract all the lines that start with a
> number or letter, then sort those results, eliminating duplicates, and
> place them in an output file.
>
> I seem to have all the right parts, but cannot get them to work
> together:
>
> cat input.txt | grep '^[0-9][a-z][A-Z]' | sort -u > output.txt
>
> Any help?
>
> Thanks!
try this
cat input.txt |egrep ^"[A-Z]|[a-z]|[0-9]" |sort -u > output.txt
thanks,
rengith
| |
| Geoff Clare 2007-02-23, 1:18 pm |
| rengith.jerome@gmail.com wrote, on Thu, 22 Feb 2007:
[vbcol=seagreen]
> try this
>
> cat input.txt |egrep ^"[A-Z]|[a-z]|[0-9]" |sort -u > output.txt
I think you wanted:
... | egrep ^"([A-Z]|[a-z]|[0-9])" | ...
otherwise the [a-z] and the [0-9] will match anywhere on a line.
As others have pointed out, it is simpler just to use a single bracket
expression (either "^[A-Za-z0-9]" or better still "^[[:alnum:]]").
--
Geoff Clare <netnews@gclare.org.uk>
|
|
|
|
|