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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Silly bash script needed

Status
Not open for further replies.

thedaver

IS-IT--Management
Jul 12, 2001
2,741
US
I want to create a .tar-chive of the files that match a grep

"grep -Hl sutton *"
"tar zcf sutton.tar.gz"

how do I pipe grep's output of filenames into the command line parms read by tar?

Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
 
Did you try: grep -Hl sutton *|tar zcf sutton.tar.gz

IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
MS Certified Windblows Rebooter
 
Yeah, tar borks:

"tar: Cowardly refusing to create an empty archive"

I did it this way:

# grep -Hl sutton * > temp.txt
# tar zcf sutton.tgz `cat temp.txt`

I *thought* that your way was the right way, but I apparently have more to learn about how tar handles piped IO. Situation solved, mystery remains.

Thx aixmurderer. Still open to discussion.

Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
 
Plamb, that will totally not work.

tar zcf sutton.tgz $( grep -Hl sutton * )

backticks have been depricated for about 8 years now,
the $( ... ) syntax nests better and is more readable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top