Making backup to .doc file .... sh


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Making backup to .doc file .... sh
# 1  
Old 12-09-2010
Making backup to .doc file .... sh

im tring to make backup to the files end with "doc" extension but the code give me error ... what is the problem!!!!




Code:
#! /bin/sh


if [ "$1" = "-k" ]
then

    for name in `ls *.DOC`
    do
        kk= $(printf "%s_temp" $name)
        cp $name $kk
    done

else
echo "error"


Last edited by pludi; 12-09-2010 at 11:35 AM.. Reason: code tags, please...
# 2  
Old 12-09-2010
Quote:
Originally Posted by maga6610
im tring to make backup to the files end with "doc" extension but the code give me error ... what is the problem!!!!
You are pasting _temp to the end of filename.doc, which gets you filename.doc_temp.

"for FILE in `ls *.DOC`" is a combo useless use of backticks and useless use of ls *. Literally useless -- for "FILE in *" would do the same thing.

In case you end up with ".doc" instead of ".DOC" I'd suggest using [dD][oO][cC] instead of hardcoded uppercase:

Code:
for FILE in *.[dD][oO][cC]
do
        BACKUP="${FILE/.[dD][oO][cC]/.temp.doc}"
        echo mv "$FILE" "$BACKUP"
done

# 3  
Old 12-09-2010
thanx for reply

but it is not working!!!!
# 4  
Old 12-09-2010
Please do not PM me to get a faster response.

In what way is it "not working"? What does it do? Did you remove the echo from in front of mv? I put that there to make sure it showed you what it was going to do instead of trashing your files if that wasn't what you wanted...
# 5  
Old 12-09-2010
you dont need to be arrogant...
# 6  
Old 12-09-2010
You're far from the only one who's been PM-poking me and I've gradually gotten a bit sick of it.

In order to help you I need you to answer my questions. In what way is it "not working"? What does it do? Did you remove the echo from in front of mv? I put that there to make sure it showed you what it was going to do instead of trashing your files if that wasn't what you wanted.
# 7  
Old 12-11-2010
Please post

What Operating System you are running.
The current version of the script.
What you typed.
What you expected the system to reply.
How the system actually replied - verbatim.


@maga6610 When dealing with professionals it pays to be specific. Phrases like "the code give me error" and "but it is not working" are both poor English grammar and not much help towards resolution of your problem.

Ps. I can be just as arrogant as anybody.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Making HDD backup in sun Solaris system

Hello to all, I have Fujitsu Celzius M470 workstation which has Sun solaris system installed and want to make a complete backup of the hard drive. The existing HDD is SATA II, 500 GB. I don't have much experience working with SUN solaris systems (not at all) but have some experience with... (5 Replies)
Discussion started by: Mick
5 Replies

2. Web Development

Help with opening/viewing doc file via linux terminal

I am currently trying to open a .doc file in my workstation via terminal. This is my code: root@ojt:/home/ojt/Desktop# cat arts_life.doc and it gave me a bunch of unknown characters together with the contents of the doc file. What I actually want to happen is that it will open the... (4 Replies)
Discussion started by: chams
4 Replies

3. UNIX for Dummies Questions & Answers

Help with opening/viewing doc file via linux terminal

I am currently trying to open a .doc file in my workstation via terminal. This is my code: root@ojt:/home/ojt/Desktop# cat arts_life.doc and it gave me a bunch of unknown characters together with the contents of the doc file. What I actually want to happen is that it will open the... (2 Replies)
Discussion started by: chams
2 Replies

4. Solaris

Making backup with ufsdump to remote mounted filesystems

Hi Unix members. I am trying to make a backup to remote mounted filesystems : fileraseing:/vol/oracliente_revap01 10G 1.3G 8.7G 13% /orarev_ap01 fileraseing:/vol/bobje 10G 5.9G 4.1G 60% /bobje But I am receiving the follow message when use the ufsdump command: :$PWD>ufsdump 0fu... (8 Replies)
Discussion started by: aggadtech08
8 Replies

5. Shell Programming and Scripting

Open and work on a .doc file with bash script

Hello there....unix users :) I hope you can help me with this: I need open a doc file or xls files and work this files whit a bash script. For example: Open a doc file and copy information from a txt file in this doc file or xls file. Is it possible? Sorry for my english...I'm chilean... (3 Replies)
Discussion started by: bobbasystem
3 Replies

6. UNIX for Dummies Questions & Answers

looking for patterns/tex in a .doc file

I'm learning Unix on my mac, and know that the grep command only works in text files. But what if I want to search for text/patters in a doc file, say? (I write my letters in NeoOffice and save them in .doc format). Is there a unix command that can do that? (4 Replies)
Discussion started by: Straitsfan
4 Replies

7. Shell Programming and Scripting

[problem] making a backup files

Hi guys, I'm a little stuck on this problem, I've tried googling it and some trial and error but can't seem to get it working. Basically I need the script to: 1) create a directory called "mybackups", if it doesn't exist 2) go through all the .sh files in the current directory, and copy... (4 Replies)
Discussion started by: chazij
4 Replies

8. Shell Programming and Scripting

If doc file exist remove

I need help running a script. I have the script looking into a folder and converting .doc files to .odt. The script works fine except that I want it to only run when .doc files are present. If I can do this then I can put .xls files and .ppt files in the folder and convert them when they are... (2 Replies)
Discussion started by: handband2
2 Replies

9. UNIX for Dummies Questions & Answers

Check backup file size on backup tape

Hi, I performed backup on tape and I want to append more files to my previous backup on the same backup tape. But before I do that I need to know the backup file size of the first backup I performed so that I know the available size on the backup tape. Can someone help me what command I will use... (0 Replies)
Discussion started by: ayhanne
0 Replies

10. UNIX for Dummies Questions & Answers

deleteing .doc file

hi i ama dunmmies in Unix. I created a .doc file and copied it to unix via FTP as a ,doc file itself i want to delete that file , i tried with rm command it does not work file name is DDL's.doc plz help :confused: (2 Replies)
Discussion started by: agarwalniru
2 Replies
Login or Register to Ask a Question