Store the name of an extracted file to a temp file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Store the name of an extracted file to a temp file
# 1  
Old 10-25-2013
Store the name of an extracted file to a temp file

What would be the best way to store the name of an extracted file from a tar to a text file?

I want to extract one file from a tar and store the name of the extracted file to a temp file.
Code:
tar -xvf tar_file.tar file_to_be_extracted

# 2  
Old 10-25-2013
It depends on the command used to create the tar archive. If
Code:
tar tf tar_file.tar | grep filename

produces something like: ./filename or ./dir1/dir2/filename then if you use EXACTLY what tar tf showed, this will work - I picked one arbitrary name: ./filename
Code:
cd /tmp
tar xf /path/to/tar_file.tar  ./filename
mv ./filename  /path/to/tempfilename

if tar tf shows some name of the file without a leading dot ex: /path/filename
Then the /path directory has to be writable by your process. And /path/filename should not exist because tar will overwrite it.

then try:
Code:
tar xf /path/to/tar_file.tar /path/filename
mv /path/filename /path/to/tempfilename

This User Gave Thanks to jim mcnamara For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add coordinates to line of output extracted from input file

I am trying to compare/confirm the output of an script using the perl below, which does execute. However I can not seem to print $1 and $2 in each line of the input separated by a tab in each line of the output. The input file is quite large so I have only included a portion, but the format is the... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Shell Programming and Scripting

Can we store a value in temp variable which can accessible?

Hi techies I am trying to write a script which can give me a ATP of a job, My idea is : store a value in a temp variable, next script read the variable in next call of it and give me the diff of values which is ATP, as script is running every hours. Can we do this in Shell Script. If... (5 Replies)
Discussion started by: atul9806
5 Replies

3. Shell Programming and Scripting

Lookup on large file based on a temp file

hello guys Please help me with the below issue I have two files one base file another lookupfile base file abc-001 bcd-001 cde-001 Lookupfile abc-001|11|12 abc-001|11|12 abc-001|11|12 (6 Replies)
Discussion started by: Pratik4891
6 Replies

4. Shell Programming and Scripting

unrar - get the name of extracted file

If I have a script that is using unrar e file.part1.rar How does the script get the name of the extracted file if I don't know the extension of the file? In my example the name would be file.***, but I wouldn't know the extension. ---------- Post updated at 05:13 PM ---------- Previous... (0 Replies)
Discussion started by: locoroco
0 Replies

5. Shell Programming and Scripting

include file name to extracted files

I've written the script below to merge only .txt files that exist in one directory into one huge .txt file and ignore other files with other extensions. now the result is one huge .txt file with all the contents of other .txt files how can i add a File Name as a comment before each file? ... (12 Replies)
Discussion started by: miss_dodi
12 Replies

6. Shell Programming and Scripting

Error running a .sh script when extracted from a jar file.

I am trying to run a script called install.sh as follows: I get a jar file, and extract it using the command: unzip filename.jar -D path/to/files then I navigate to that directory where I extracted the files, and run the command: sh install.sh (where install.sh is one of the files... (12 Replies)
Discussion started by: albert_newton
12 Replies

7. Shell Programming and Scripting

find and replace a string in a file without the use of temp file

Hi - I am looking for a replacing a string in a in multiple *.sql files in directory with a new string without using a temporary file Normally I can use sed command as below for W in ls `FILE*.sql` do sed 's/OLD/NEW/g' $W > TEMPFILE.dat mv TEMPFILE.dat $W done But Here in my... (9 Replies)
Discussion started by: raghutapal
9 Replies

8. UNIX for Dummies Questions & Answers

Updating a field in a File without creating temp file's

Hi Experts, I have a requirement where i need to update the below items in file, 1. END TIME 2. PREV_STATUS For the first time the PREV_status and end time of all job the job will be sysdate & NULL reply as below, Session_name,Load Type,Frequency,Seesion End time,Prev_Status... (2 Replies)
Discussion started by: prabhutkl
2 Replies

9. UNIX for Dummies Questions & Answers

To send an email with the body content extracted from a file

Hi, I have been trying to shoot an email with the email body to be obtained from a file. Can someone please help me with it.. I have been trying to use the MAILX commad for the same. mailx -s "test email" -r sender@test.com < file.txt but it sends the file as an attachment,while i... (3 Replies)
Discussion started by: rohit.shetty84
3 Replies

10. Shell Programming and Scripting

Append to end of each line of file without a temp file.

Hello I am trying to append an incrimenting number to the end of each line I have it working with a temp file. But I want to do this without a temp file. a=1 cat "file" | while read LINE do echo "$LINE, $a" >> filewithnumbers a=`expr $a + 1` ... (4 Replies)
Discussion started by: rorey_breaker
4 Replies
Login or Register to Ask a Question