Help with searching for a file in a directory and copying the contents of that file in a new file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with searching for a file in a directory and copying the contents of that file in a new file
# 1  
Old 03-04-2011
Error Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here Smilie

I need a script that can search for a file in a directory and copy the contents of that file in a new file.

Please help me. Smilie Thanks in advance~
# 2  
Old 03-04-2011
Instead of us doing your work for you, why not give it a shot yourself, run it, debug it, and come to us with specific questions about why particular lines in your code don't work?
# 3  
Old 03-04-2011
hint, hint...

probably going to use the following commands
Code:
ls
cp

# 4  
Old 03-04-2011
here's the script

I am creating a simple script that can "recover" a deleted file.

I already created a working del command wherein when I type
Code:
$ del filename

, the filename will be moved to a directory called recyclebin.

Now, in order for me to recover this file, I need to search for the filename inside the recyclebin and move it to the destination that the user will specify.



Code:
#!bin/bash
dest=$2

if [ !-d $dest ]

        echo "Error: The path $2 does not exists"

        else
                continue

                notFound=`find ~/.recyclebin -name $1`

                if [ $notFound != "false" ]

                        fname=$1

                        cp $fname $dest/${fname}1

                fi
fi

unfortunately the code does not work Smilie

What is wrong with my code?

I just want the script to be executed something like this:

Code:
 $ rcvr filename ~/destination

Please help me, thank you.
# 5  
Old 03-05-2011
How about checking out the thread you already made about this a few hours ago? It got some answers.
# 6  
Old 03-05-2011
thanks

I already read your answer on the other thread. I have another problem. Please respond, thanks. and I apologize for always asking help.
# 7  
Old 03-05-2011
Quote:
Originally Posted by zel2zel
I already read your answer on the other thread. I have another problem.
No, it's not -- you're still making all the same mistakes I corrected in the other thread. Read it again.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Rename file in directory using contents within each file

In the below there are two generic .vcf files (genome.S1.vcf and genome.S2.vcf) in a directory. There wont always be two genaric files but I am trying to use bash to rename each of these generic files with specfic text (unique identifier) within in each .vcf. The text will always be different, but... (11 Replies)
Discussion started by: cmccabe
11 Replies

2. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

3. UNIX for Beginners Questions & Answers

Copying Contents of a file

Hello all. Is there a command to copy the contents of one file into another file as the first line? (1 Reply)
Discussion started by: 2metal4u
1 Replies

4. Shell Programming and Scripting

Problem with the awk in searching the contents in a file

Hello all, I am a newbie in awk. I am struggling in this problem for a long.Actually I have two files, filea and fileb. File a is actually a search key through it I have to find the corresponding japanese tag from file b. filea contains the data like this: sm982882 sm1893548 sm2420025... (3 Replies)
Discussion started by: csim_mohan
3 Replies

5. Shell Programming and Scripting

Help in searching a particular string in a file name (not inside the file contents)

Dear Unix Gurus, I am new to shell scripting and in the process of learing. I am trying to find whether a file name has today's date in MMDDYYYY format. I am using the following code and it doesn't seem like working. #!/usr/bin/ksh today=$(date '+%m%d%Y') echo today: $today file=`find... (4 Replies)
Discussion started by: shankar1dada
4 Replies

6. Shell Programming and Scripting

Need help with searching and copying in a text file

Hi, I need help searching through a large text file. I need to find a certain string within the text, and copy each line until another string appears. The file looks like this: >scf15164843 ATTAAAGGNNNGGAATTTCCCCAA ATTACCGGCTTTAAANNNTTACCC >scf15154847 CCGGGNNNTTTAAACCCGNGNGCC... (2 Replies)
Discussion started by: repiv
2 Replies

7. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

8. Shell Programming and Scripting

searching and editing file contents

Can you please help me to edit parts of a file and write into a new file. ===================================== Suppose I have a huge data dump in a file I need to search for a tag in that and cut few lines around that tag in the file. Is there a way to keep track of line numbers and operate on... (18 Replies)
Discussion started by: jayana
18 Replies

9. UNIX for Dummies Questions & Answers

copying a file from one directory to another

Hi This is my first day in Unix, and I am trying to copy a file called holiday.txt from my D drive into the C drive folder called h like currently i am in D drive, i want to copy my holiday.txt into C\h (C drive, h folder) i am able to copy the file in the same drive, but how to do the... (5 Replies)
Discussion started by: soujanya_srk
5 Replies

10. UNIX for Advanced & Expert Users

Searching contents of a file

Is there a way a command or a combination through which i can check the contents of a all files in a directory and get the return as the file names which contains the partiuclar string. (2 Replies)
Discussion started by: thepitzaboy
2 Replies
Login or Register to Ask a Question