To Tar files which are not present

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To Tar files which are not present
# 1  
Old 11-13-2013
To Tar files which are not present

Hi guys,

I need how its possible to tar group of files even though the respective file is not present for eg in my home folder

my script looks like below by reading the content from file.txt and creating tar out of it can any one help on the below query

a=`more file.txt`

tar -cvf test.tar $a

where my file.txt contains

but 3.csv doesnt exist in my home folder i need

test.tar to contain 1.csv and 2.csv

# 2  
Old 11-13-2013
test.tar will only contain 1.csv and 2.csv if 3.csv does not exist.

What exactly is the problem?

If it's the error message, you can easily remove that by adding this to the end of the tar line:
2> /dev/null

# 3  
Old 11-13-2013
How about using

option in tar to exclude 3.csv ?

Between, even though you might get this error, tar creates a test.tar Smilie
tar: 3.csv: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

# 4  
Old 11-13-2013
@scott my problem is to to exclude 3.csv and to create tar for 1.csv and 2.csv since both these files are present in my folder but 3.csv doesnt.why iam saying is since i am reading the content from file.txt which is a static file.
# 5  
Old 11-13-2013
And, as I said, if 3.csv doesn't exist, it will be excluded.
$ echo "a.csv
c.csv" > files.txt

$ touch a.csv b.csv

$ ls -l
total 8
drwxr-xr-x  5 scott  staff  170 Nov 13 19:03 .
drwxr-xr-x  5 scott  staff  170 Nov 13 18:48 ..
-rw-r--r--  1 scott  staff    0 Nov 13 19:03 a.csv
-rw-r--r--  1 scott  staff    0 Nov 13 19:03 b.csv
-rw-r--r--  1 scott  staff   18 Nov 13 19:02 files.txt
$ tar cvf test.tar -T files.txt 2> /dev/null

$ tar tvf test.tar
-rw-r--r--  0 scott  staff       0 Nov 13 19:03 a.csv
-rw-r--r--  0 scott  staff       0 Nov 13 19:03 b.csv

# 6  
Old 11-13-2013

i dont want the execption to be handled as null becoz it would be a valid exeception if it fails with some other reason
# 7  
Old 11-13-2013
Garbage in garbage out. Sanitize first.

for f in `more file.txt`; do [[ -e "$f" ]] && echo "$f"; done >  sanitized.list
tar -cvf test.tar -T sanitized.list

Last edited by Aia; 11-13-2013 at 05:02 PM.. Reason: Redirect outside the for loop
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

2. Shell Programming and Scripting

Joining files present in different directories.

Hi Experts, I have files Bank1 ,Bank2 ,Bank3 with high level customer information in one folder. /home/Cust_information/ Bank1,Bank2,Bank3,Bank4 The detail level information of all customers of each Bank are present in separate directories . Here Bank1 is a directory which contains set... (2 Replies)
Discussion started by: bharathbangalor
2 Replies

3. Shell Programming and Scripting

Compare two numbers which present in two different files

Hi, I need to compare the two floating or integer numbers which present in two different files, Ex: File 1: col1 col2 col3 11 ssa 13.60 12 ssb 11.00 13 ssc 754.00 File 2:col1 col2 col3 11 sa 12.75 12 sb 11.00 13 sc 763.00 here i have to compare 3 column if 1st column match,... (8 Replies)
Discussion started by: Shenbaga.d
8 Replies

4. Shell Programming and Scripting

Checking in a directory how many files are present and basing on that merge all the files

Hi, My requirement is,there is a directory location like: :camp/current/ In this location there can be different flat files that are generated in a single day with same header and the data will be different, differentiated by timestamp, so i need to verify how many files are generated... (10 Replies)
Discussion started by: srikanth_sagi
10 Replies

5. Shell Programming and Scripting

List all the files in the present path and Folders and subfolders files also

Hi, I need a script/command to list out all the files in current path and also the files in folder and subfolders. Ex: My files are like below $ ls -lrt total 8 -rw-r--r-- 1 abc users 419 May 25 10:27 abcd.xml drwxr-xr-x 3 abc users 4096 May 25 10:28 TEST $ Under TEST, there are... (2 Replies)
Discussion started by: divya bandipotu
2 Replies

6. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

7. UNIX for Dummies Questions & Answers

search a word in a file present in tar file

i need to search a word in the tar file. if it is present just give me the file name please help me (1 Reply)
Discussion started by: junkbuster
1 Replies

8. Shell Programming and Scripting

check whether 3 files are present

I'm trying to check whether 3 files are existing and send 3 files as attachements. If only two are there then send those two files as attachments. if ; then elif ; then I tired the above given syntax and then it is giving me an error line 11: ' I tried with -a instead of && and... (3 Replies)
Discussion started by: Celvin VK
3 Replies

9. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

10. Shell Programming and Scripting

PERL: print if files present

FOR: Windows NT 4 I want perl to read a directory. there is suposed to be two files in the folder ( file1.ini and file2.ini ) and i want perl to print "Files present" or "Files NOT present" to a text document ( report.txt ) how do i do it.? (2 Replies)
Discussion started by: perleo
2 Replies
Login or Register to Ask a Question