Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tar command - include wildcard?

Status
Not open for further replies.

chibaru

Programmer
Aug 24, 2005
13
US
Hi,
I have a tar file with a directory that has subdirectories with reports in them. I would like to to extract only one report from all subdirectories. Is it possible to have a wildcard using an include file?

For example, in this tar file, I only want rpt1 from subdirA and subdirB:
2006-03-31/subdirA/rpt1
2006-03-31/subdirA/rpt2
2006-03-31/subdirB/rpt1
2006-03-31/subdirB/rpt2

I used this command:
tar xvf /export/home/user/rptbkp.20060331.tar -I /opt/ctlcard/tar_rpt_rpt1

The include file, tar_rpt_rpt1 has:
./2006-03-31/*/rpt1


 
How about:

Code:
tar -ft /export/home/user/rptbkp.20060331.tar |
while read fn; do
  if [[ $(expr "$fn" : ".*subdir[AB]\/rpt1$") -gt 0 ]]; then
    tar -xvf /export/home/user/rptbkp.2006331.tar "$fn"
  fi
done

Do this in your folder of choice and expect the old directory structure to be reproduced from that point on. I don't have the -I option in my version of tar in HP-UX, so you're left with that.

Cheers,
ND [smile]

[small]bigoldbulldog AT hotmail[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top