Programming :: Shell Script To Delete File If It Exists

Aug 10, 2010

I am writing a shell script to delete a file if it exists.

View 11 Replies


ADVERTISEMENT

Programming :: Delete A Line From File Using Shell Script?

Oct 16, 2010

i have a file containing contents as

1 2 3
2 2 3
11 2 3

now i want to delete the line which first column content is 1. so, if i pass the parametere 1 to function delete_row. is should remove the first row as

2 2 3
11 2 3

and then write the contents in file.

View 2 Replies View Related

Programming :: Search File By Pattern And Then Delete Corresponding Lines In Shell?

Sep 16, 2010

I have such a file(test.txt):

abc 123 456
abc 256 145
axd 125 225

[code]...

View 8 Replies View Related

Programming :: Shell Script To Delete Files Which Location Should Be Read From Log File

Jun 26, 2010

I have 2 external hdd in wich I have all my files. yesterday, I have copied all the files from hdd2 to hdd1 and I want to eliminate duplicates so I used FSLint to find them,now I want to make a shell script to delete all the files/entries (read from the log file) that begin with.

View 14 Replies View Related

Programming :: Finding A Shell Script To Delete Files Which Location Should Be Read From A Log File?

Jul 16, 2011

I have 2 external hdd in wich I have all my files.... yesterday, I have copied all the files from hdd2 to hdd1 and I want to eliminate duplicates so I used FSLint to find them, now, I have a txt file that looks like this:

Code: /media/My Book/!!!MIS DOCUMENTOS/Documentos/2 sep2003-jun2009 USB/!TESIS/TESIS/TESIS CVT LABVIEW Y CODEWARRIOR/LabVIEW85RuntimeEngineFull.exe /media/My Book/HDD_Toshiba/Borrable/Pen_Drive_4GB/Tesis/Super CD de la tesis/LabView/LabVIEW85RuntimeEngineFull.exe multiplied by millions of entries...

now I want to make a shell script to delete all the files/entries (read from the log file) that begin with:

Code:

/media/My Book/HDD_Toshiba/**** Since HDD_Toshiba is the folder in hdd1 (MyBook) that contains all the files from hdd2

View 1 Replies View Related

Fedora Servers :: Cannot Delete Directory 'foo': File Exists

Jan 17, 2009

I was transferring some files from my laptop (running FC6) to a server at my work (don't know what kind) with "scp -rpC" and it stalled, don't know why.
Now when I try to delete the files from the server so I can start again I get the following error message

Code:
rm -r Single_injections/
rm: cannot remove directory `Single_injections/195320/400mA/010': File exists
rm: cannot remove directory `Single_injections/195320/400mA': File exists
rm: cannot remove directory `Single_injections/195320': File exists
rm: cannot remove directory `Single_injections': File exists

[Code].....

View 6 Replies View Related

Programming :: Check If Directory Exists Using Shell Script

Apr 20, 2009

I am trying to write some small script file that will check if a USB stick is connected to my pc or not. I can't seem to get it to work, but I am sure it is a very simple fix.

I am running on Fedora core 10.Can anyone help me figure out what the problem is?If I run these lines through console it works fine (meaning, I type the commands in this file straight in the command line/console).

View 9 Replies View Related

Programming :: Shell Script To Check Whether Directory Exists On Remote Server

Jan 17, 2011

I am new to scripting, would like to have a script that tests whether a directory exists on remote host & display the message accordingly. The remote hostname can be provided by means of file containing list of hostnames. Can use rsh for connecting to remote host.I tried with couple of scripts by searching google but didn't get desired result. Please help me, below is my efforts, $file contains list of hostnames.

View 10 Replies View Related

Programming :: Delete Line Of Text From Text File Via Shell?

Jan 13, 2010

I have to delete a certain line of text from the a textfile via ubuntu's shell scripting.I have done research, and it seems that most people advocate the usage of sed /d option. sed makes does not edit the text file. Hence, most options I discovered involved the use of a temporary variable/textfile and then overwriting the old file with the temporary new file. Is there anyway whereby I can bypass the use of temporary storage containers? I hope there is any magical combination of commands to edit the file directly.

View 3 Replies View Related

Programming :: Shell Programming - Delete User Input

Jan 21, 2011

I recently started shell programming and my task now is to do a menu display.Currently i am stuck whereby user will input both title and author and it will delete it.

Do i have to use sed command?

View 4 Replies View Related

Programming :: Check If There Is Any Ejb File Exists In The Directory

May 1, 2011

I have a directory called /data In this directory I have some files like abcejb.jar,12_ab_ejb.jar, shejb.jar, test I need a shell script like... 1st I want to check if there is any ejb file exists in the directory using some condition If ejb files exists I want to redirect the ejb files list to a file called list. Now I want to copy all the files in the list file to some remote system.

View 1 Replies View Related

Programming :: Bash - Statement To Check If A File Exists Or Not?

Oct 6, 2010

This script that I found online does the job it promises. it does convert the files to mp3 without an issue. What I need to include now is an if statement that says If $file.mp3 exists then delete $file.wav

Code:
#!/bin/sh
# name of this script: wav2mp3.sh
# wav to mp3
# Credit to the script creator (Nikesh Jauhari):

[Code]...

After that I'm stumped as to how to do the if statement

View 14 Replies View Related

Programming :: Restart Apache If File Doesn't Exists?

Jun 6, 2009

I'm running CentOS 5.3 64bit and from the get go I've had problems with the Apache serverMore specifically, on what seems to be a random occurance, the apache server stops to respond.The process is still running, but nothing happens with it, and it is not responding.The /var/logs/httpd/error_log is blank for the occurance and only shows an entry after I give it a restartSo I'm a bit confused about what is going on.With that said, I need to make sure the httpd is working one way or another.I don't want to force a restart service every 10 minutes as this seems a bit too much.However, I do want to have the following:run a crond every minute to do:

rm -Rf /root/testarea/*
wget http://ip/work.gif
then check if work.gif exists.

[code]...

View 1 Replies View Related

Programming :: Check That The Same File Exists Within Two Different Directories Using A Filename As A Variable?

Apr 30, 2010

I am in need of a way to check that the same file exists within two different directories using a filename as a variable. Here is the process which requires it: The script is reaches out (via ftp) and pulls down a file(s) and delete it afterwards. This is halfhazard because in the instance it doesnt pull down the file, yet still deletes it, we are up a creek. I am looking to pull it down to a temp location and then verify that file exists in the location in which it needs to be present to process before deleting it, adding a little extra layer for security. The script itself is finished.If I put a file name in manually it works perfect. I just need a way to pump the filename into the variable.

View 1 Replies View Related

Debian Programming :: Check If Files Exists By Read Input From A File

Jul 27, 2013

I need a script that dose the following checks if files exists by read input from a file then compares them to the files listed in the directory if they don’t exists the script would report back which file dose not exists. I also need to format the output so that files are grouped in different groups, group A, B, and C and etc based on file name. I would like the output of that do not exists files to be sorted based on second number in the file name than group according. I understand some of the basics of bash scripting something along of the lines of a loop and if statements might do the trick. Below is what I have so far. I don’t car so much about the script reporting back the file exists I prefer to only know if the file is missing and is less than 3 days old. Problem is if a file dose not exists in the reports file the test compares against the wrong file.

Group A

Foo22000.tar.gz
Foo22010.tar.gz

Group B

foo25000.tar.gz
foo25100.tar.gz

Group C

foo26000.tar.gz

Code] ....

View 2 Replies View Related

Programming :: Made A Shell Script To Copy And Delete Files Through FTP?

Feb 13, 2011

I have made a shell script to copy and delete files through FTP.I want to first delete all txt files and then mput all txt files.

Code:
ftp ()
{

[code]....

View 6 Replies View Related

Programming :: Shell Script To Automatically Delete Files With The Same Name As The Parent Directory?

Mar 18, 2010

I am facing a problem in Windows due to a virus called Newfolder.exe which creats files with the same name as it's parent directory and an extension .exe and this happens for every directory in the entire hierarchy in the infected pen drive. The antivirus detects them, but is sucking slow. So I thought this is a good opportunity to use the concepts of the all mighty shell script to remove those as they follow the same pattern. Say my complete path is

Code:

/home/pkd/fol1/

The virus would have created an file with complete paths

Quote:

/home/pkd/fol1.exe

If fol1 has two more directories fol11 and fol12 Then there would be two more .exe(virus created) in the following path

Quote:

/home/pkd/fol11/fol11.exe
/home/pkd/fol12/fol12.exe

View 1 Replies View Related

Programming :: Create/delete Temp/backup Files Through A Shell Script?

Dec 31, 2008

I have a shell script that need to create some files:

1) backup files of user passed in file ( that will be written by this shell ).

2) temp files that the shell will create and later delete/remove.

This shell script will be used from my local dir ( I am not a super or a sysadmin ). Users of this shell will call this script to run on their local files in their respective directories. When my script runs, it errors with the following:

cp: cannot create regular file `./listfile.txt.backup': Permission denied
/home/myUser/tools/myShellScript: line 12: listfile.txt: Permission denied

for the temp I was able to avoid this error by creating the temp file in the /tmp directory. All I want is for this shell script to run, create/modify/backup files in user's local dirs.

The user dir has the following permission:

drwxr-xr-x testDir

the file that needs to be backed-up has:

-rw-r--r-- listfile.txt.

View 7 Replies View Related

General :: Delete A File On A Remote Server Using Shell Scripting?

Jul 18, 2010

delete a file on a remote server using shell scripting.

View 14 Replies View Related

Programming :: Shell Script To Delete Part Text Of A Line If Pattern Matches?

Apr 12, 2010

I am trying to create a shell script, on taking a input file as parameter, which need to do 3 things

1) create a copy of existing file.

2) add a new line to the copied file.

3) strip off all the absolute paths inside the copied file

The first 2 points are straight forward. but i am finding it difficult to acheive the 3rd point. myself not very good with awk and sed. but gave it a shot in vain. For example, the input script consists of below,

PROGRAM=`/usr/bin/basename $0`
HOST=`/usr/bin/uname -n`
echo Start $PROGRAM `/usr/bin/date` |
/usr/bin/tee -a $LOG

The output of the script should look like,

PROGRAM=`basename $0`
HOST=`uname -n`
echo Start $PROGRAM `date` |
tee -a $LOG

View 14 Replies View Related

Ubuntu :: Make Shell Script To Delete Selected Entries Of A Log File?

Jun 26, 2010

I have 2 external hdd in wich I have all my files.... yesterday, I have copied all the files from hdd1 to hdd2 and I want to eliminate duplicates so I used FSLint to find them, now, I have a txt file that looks like this code...

now I want to make a shell script to delete all the files/entries (read from the log file) that begin with code...

View 2 Replies View Related

General :: Shell Script To Delete File If A Pattern Is Found And Restart Servers?

Jul 22, 2010

I have requirement to delete some log files from a directory if a string"deletethisfile" is found.Then restart the application servers.1. Search for the string ?deletethisfile? in server.log file under a directory, If found 2. Stop that particular server.3. Delete the log file 4. Restart the server.

View 2 Replies View Related

Programming :: Sed Delete Lines From File One If Regexp Are Listed In File Two?

Sep 17, 2009

I am trying to delete lines of a file if they contain text that is present on another file. For example

> cat one.txt:

a
b
c
d

[code]....

I get the following output:

> ./test.sh one.txt two.txt
a
b
d
e

[code]....

View 6 Replies View Related

Programming :: Parsing Xml File Using Shell Script And Generate Report In A PDF File?

Jul 9, 2009

parsing xml file using shell script and generate report in a PDF file

Xml file input:

<report>
<student name="x" father name="x1" class="first" Address="xyz">
<property name="sports" value="yes"/>
<property name="drawing" value="no"/>

[code]....

View 12 Replies View Related

Programming :: Gawk - Delete Line In File?

Oct 13, 2010

I want to delete lines which contain the word "Fehler" but for some reason my programm isn't working:

Code: BEGIN { FS="|"
OFS="|"
SUBSEP="|"

[code]...

View 6 Replies View Related

Programming :: Bash - Delete Only One Line From A File?

Apr 9, 2011

I would like to delete a single line from a file that contains many lines passing through the same values ​​as the two parameters. Again, I would like to delete a single line and not all those that contain parameters. How can I make bash?

View 14 Replies View Related

Programming :: Delete Particular Revision Of File From SVN Repos ?

Dec 23, 2010

I am using Subversion version1.2 and need one favour. I have written code to delete particular revision from SVN Repository. Unfortunately, i couldn't delete particular version from repository. Any one can response me.. how to delete?

View 6 Replies View Related

Programming :: Delete Line In File Matching String?

Jan 26, 2010

Quote:Originally Posted by topcatI would like to know how i can write a shell script to delete a line if a particular pattern exists?E.g. I have a text file with multiple lines. Say 1000s. in the following pattern.

username@email.com:149.0.3.4:1
username1@email.com:149.0.3.4:1
username1@email.net:149.0.3.4:1
username1@email.edu:149.0.3.4:1

If the patternusername@email.com exists then the line "username@email.com:149.0.3.4:1 should be deleted from the file.I have a very similar question but I need to delete one line in a file which matches one very precise instance of a string only. Let's assume I have a file composed of thousands of lines and let's call the file chap-secrets. Let's take the following sample entries:

Code:
#USERNAME SERVER PASSWORD IP
pp pptpd blahblah *

[code]....

View 7 Replies View Related

Programming :: Delete Multiple Lines In A File Using Perl?

Apr 15, 2011

I have a file looks like the following:

digraph topology
{
"192.168.3.254" -> "10.1.1.11"[label="1.000", style=solid];
"192.168.3.254" -> "10.1.1.12"[label="1.000", style=solid];

[code]...

Order of these lines are random... So I cannot delete line #19, for example... And you can see that top four lines I want to delete are pairs. So there might be some clever way to detect the lines, if a line has both "1.9" and "1.11", then delete the line... I am new to perl language. The following is the code I have now... I think I just need to write some code inside the while loop checking if I want to delete the line $dotline before I write to a NEW file.

Code:

#!/usr/bin/perl -w
$TOPPATH = "/tmp";
$NAME = "topology";
$FILENAME = "$TOPPATH/$NAME.dot";

[code]....

View 16 Replies View Related

Programming :: Search For A Word In A File And Then Comment It Or Delete It?

Aug 9, 2009

I want to know that how can i search for a word in a file and then comment it or delete it. I know this command works.

sed 's/word/#word/'g inputfile > outputfile

But the lines in my input file are as under:

zone "abc.com" { ---- This line can be comment
type master; ----- This line repeat again and again in the file
file "abc.txt";
allow-query { any; }; -This line repeat again and again in the file
};

I want to know how can i comment a certain zone.

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved