[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] group
From: |
Val Krem |
Subject: |
Re: [Help-bash] group |
Date: |
Tue, 13 Dec 2016 00:40:32 +0000 (UTC) |
John and Greg,
Thank you so much for the help.
Val
On Monday, December 12, 2016 9:11 AM, John McKown <address@hidden> wrote:
On Mon, Dec 12, 2016 at 7:25 AM, Greg Wooledge <address@hidden> wrote:
> On Sat, Dec 10, 2016 at 07:52:22PM +0000, Val Krem wrote:
> > The file names look like as follow.
> > Region-19940726.csv
> > Region-19940816.csv
> > Region-19940920.csv
> > Region-19941018.csv
> > Region-19941122.csv
> > Region.csv
> > RegionAB-19940726.csv
> > RegionAB-19940816.csv
> > RegionAB-19940920.csv
> > RegionAB-19941018.csv
> > RegionAB-19941122.csv
> > RegionAB.csv
> >
> > The first file (file1) should include all files that starts with
> 'RegionAB' and inlcude the following files
>
> cat RegionAB-*.csv RegionAB.csv > file1
>
>
> > The second output file (file2) should include all files that start
> with 'Region'
> >
> > Region-19940726.csv
> > Region-19940816.csv
> > Region-19940920.csv
> > Region-19941018.csv
> > Region-19941122.csv
> > Region.csv
>
> cat Region-*.csv Region.csv > file2
>
>
Greg gave you the canonical answer. But, if you just want to read those
files and (1) you don't want to merge them together into a cumulative file
(perhaps due to space) and (2) your application is not written to handle
multiple separate files, I will mention "process substitution". In most
shells, you might need to do something like:
cat Region-*.csv Region.csv >tempfile.csv
some-program tempfile.csv
rm tempfile.csv
But with BASH, you can use process substitution:
some-program <(cat Region{,-*}.csv)
Of course, the above only works if "some-program" only wants to _read_
those files, not update them.
And, just to be complete, note that "Region{,-*}.csv" expands into
"Region.csv" and "Region-*.csv" and then "Region-*.csv" expands into every
file which starts with "Region-" and ends with ".csv". I don't know how
many people use the {} or "brace expansion". But I really like it for
three reasons (none really good): (1) I'm lazy and don't like to retype
stuff; (2) it "looks cool"; (3) it messes with other people's minds.
--
Heisenberg may have been here.
http://xkcd.com/1770/
Maranatha! <><
John McKown