tar/cpio/pax read patterns from stdin


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers tar/cpio/pax read patterns from stdin
# 1  
Old 07-25-2010
tar/cpio/pax read patterns from stdin

tar has the -T operand for reading patterns from a file.
Is there any way to read patterns from stdin, without creating a temp file? I would like to avoid iterating over the archive repeatedly (e.g. with a loop or xargs) as this is a large archive and we're only extracting a small number of specific files.
Shell is sh (ash) or csh.
Cheers

Last edited by uiop44; 07-25-2010 at 02:50 AM..
# 2  
Old 07-25-2010
Hi.

Here's an example with tar using the often-found idiom of minus "-" to signify STDIN. The input can then be from a here document, q.v., or from the keyboard. The input would be the name of a file, one per line. I would not say a pattern, however, as in filename expansion (so-called globbing), or regular expressions, unless you also use option --wildcards
Code:
#!/usr/bin/env dash

# @(#) s1	Demonstrate tar -T with STDIN as here document, keyboard.

# The Debian Almquist Shell (dash) is a lightweight
# POSIX-compliant shell derived from ash.

#-T, --files-from F
#	  get names to extract or archive from file F

pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }

# Remove debris from previous runs.
rm -f t?

pl " Contents of f.tar:"
tar tvf f.tar

pl " Files named t? before operation:"
ls -lgG t?

pl " Extract t2, as directed by a here document:"
tar xvf f.tar -T - <<'EOF'
t2
EOF

pl " Files named t? after operation:"
ls -lgG t?

exit 0

# As interactive:
# enter names, finish with EOF character, usually ^D, (control-D).

tar xvf f.tar -T -

producing:
Code:
% ./s1

-----
 Contents of f.tar:
-rw-r--r-- backup/backup     4 2010-07-25 06:47 t1
-rw-r--r-- backup/backup     4 2010-07-25 06:47 t2

-----
 Files named t? before operation:
ls: cannot access t?: No such file or directory

-----
 Extract t2, as directed by a here document:
t2

-----
 Files named t? after operation:
-rw-r--r-- 1 4 Jul 25 06:47 t2

This was run in the environment:
Code:
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0 
tar (GNU tar) 1.20

Best wishes ... cheers, drl
# 3  
Old 07-26-2010
thanks drl.
Code:
 | tar x -vzf archive.tar.gz -T -

did the job.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Cpio - input files (from list) are stored in different order inside cpio archive - why?

Due to budget constraints I have to reinvent an Enterprise backup system in a SPARC (sun4v) Solaris estate (10 & 11). (yep - reinvent wheel, fun but time consuming. Is this wise?! :confused: ) For each filesystem of interest, to try to capture a 'catalog' at the front of each cpio archive (for... (1 Reply)
Discussion started by: am115998
1 Replies

2. UNIX for Beginners Questions & Answers

Command to read between patterns in a while

I am currently working on a requirement in a file wher I have to filter the characters between two specific fields/patters and get the count of total no of characters between the two fields. REQUIREMENT: The below content is in a file 1. I have to get the no of characters between each... (6 Replies)
Discussion started by: venkidhadha
6 Replies

3. Programming

How to read extended ASCII characters from stdin?

Hi, I want to read extended ASCII characters from keyboard using c language on unix/linux. How to read extended characters from keyboard or by copy-paste in terminal irrespective of locale set in the system. I want to read the input characters from keyboard, store it in an array or some local... (3 Replies)
Discussion started by: sanzee007
3 Replies

4. Shell Programming and Scripting

Help with tar/pax

Hi, I have tar ball "data.tar" which consists of many files from different directories. If I untar a file using following command, it will untar file to location /input/data tar -xvf data.tar /input/data/abc.txt I want the file to be untar in current directory and or any other... (3 Replies)
Discussion started by: pinnacle
3 Replies

5. Shell Programming and Scripting

to read two files, search for patterns and store the output in third file

hello i have two files temp.txt and temp_unique.text the second file consists the unique fields from the temp.txt file the strings stored are in the following form 4,4 17,12 15,65 4,4 14,41 15,65 65,89 1254,1298i'm able to run the following script to get the total count of a... (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

6. UNIX for Dummies Questions & Answers

Difference between 'pax', 'tar', and cpio

Could any one please help me in understanding the difference between pax,tar and cpio. all of them basically creates archive files. (9 Replies)
Discussion started by: joshi123
9 Replies

7. Programming

Read redirected file from stdin in C (a.out < file)

Hello everybody, Having a file with the following content: 192.168.0.254->192.168.0.1 192.168.0.2->192.168.0.34 192.168.0.56->192.168.0.77 I need to code a program in C to read it from stdin redirection (i.e. root@box~# ./a.out < file), my question is, how can i do that? I've tried with... (2 Replies)
Discussion started by: semash!
2 Replies

8. Shell Programming and Scripting

[Solved] Help piping tail to read STDIN

Hello everybody, I need some help here. I have a log file that gets updated every hour approximately. I want to make some processing on each line which is added in the log file with a program written in PERL. The problem is that I don't see anything when a line is added in the log file. I... (6 Replies)
Discussion started by: Samb95
6 Replies

9. Programming

read and write stdin/stdout in unix

Hi, i am using the below program to read from the standard input or to write to standard out put. i know that using highlevel functions this can be done better than what i have done here. i just want to know is there any other method by which i find the exact number of characters ( this... (3 Replies)
Discussion started by: MrUser
3 Replies

10. Programming

read file from tar.gz archive

I want to write a c-program which reads a textfile from a tar.gz archive. How can I do it? (9 Replies)
Discussion started by: krylin
9 Replies
Login or Register to Ask a Question