Programming :: Shell Script Searching File In A Directory?

Feb 23, 2011

I am trying to search particular directory which has files with extensions like .html,.mp3,.xml etc I have a list of such files What I am doing in my script is

for file_name in `find /home/ -name index.html -o -name song.mp3 -o -name help.xml`;
do
if [ $file!='' ]
then

[code]....

I have around 100+ files name with some particular extension , this code works fine if the directory name does not have any special character in it like " "(white character) .

It is failing to give the output. IF I run the find command on the console the I am getting the correct file name with location

/home/user1/public_html/mediawiki/config/movie.mp3
/home/user1/public_html/mediawiki/movie.mp3
/home/user1/public_html/mediawiki/pop.mp3
/home/user2/public_html/index test/pop.mp3
/home/user2/public_html/index test/web.xml
/home/user2/public_html/song.mp3

If I echo the file name from the script Then output is little missed match when a directory name has special char like " "

/home/user1/public_html/mediawiki/config/movie.mp3
/home/user1/public_html/mediawiki/movie.mp3
/home/user1/public_html/mediawiki/pop.mp3

[code]....

I am not sure what is wrong with script or my code .. Does shell have un-controlled behavior of manipulating the output of any command.

View 14 Replies


ADVERTISEMENT

Programming :: Finding Maximum Length File In A Directory Recursively Using Shell Scripting?

Nov 8, 2010

I want to find maximum length file in a given directory. It should search recursivley. I want this to be done using ls and simple looping constructs.

View 6 Replies View Related

Programming :: Searching File In Directories?

Feb 23, 2011

I am trying to search particular directory which has files with extensions like .html,.mp3,.xml etc I have a list of such files

What I am doing in my script is

for file_name in `find /home/ -name index.html -o -name song.mp3 -o -name help.xml`;
do
if [ $file!='' ]
then

[Code].....

View 4 Replies View Related

Programming :: Searching Pattern In Tab Delimited File Using Grep

Mar 4, 2010

Suppose i have a file(1.txt) separated by TAB delimiter in a line

1 B AB 2
2 C AB 2

if I need to search for the records having B?? using grep.If i need to perform multiple search like line having "C and AB" or "B and AB"??

View 5 Replies View Related

Debian Programming :: Searching For A List Of Strings In File With Python

Oct 14, 2013

I'm trying to search for several strings, which I have in a .txt file line by line, on another file.

So the idea is, take input.txt and search for each line in that file in another file, let's call it rules.txt.

So far, I've been able to do this, to search for individual strings:

Code: Select allimport re

shakes = open("output.csv", "r")

for line in shakes:
    if re.match("STRING", line):
        print line,

How can I change this to input the strings to be searched from another file?

So far I haven't been able to.

View 3 Replies View Related

Programming :: Sed Script - Searching For Text Within File / Replace With Variable

Feb 25, 2011

Code:
#!/bin/bash
VARR=`cat /proc/asound/cards | grep HDMI | cut -c 1-2`
VARX="defaults.ctl.card $VARR"
VARY="defaults.pcm.card $VARR"
FILE1="alsa"
FILE2="alsa.new"
echo $VARX
echo $VARY
sed "s/defaults.ctl.card*/'$VARX'/g" $FILE1 > $FILE2

This is what I have right now. Well, I thought I knew sed, and apparently I don't... I tried writing this for someone else, and this has given me trouble, so since the user pretty much figured it out on his own, here it goes.
Say VARR=1, so VARX and VARY contain the above text, appended by 1.
What I am trying to do is replace the text "defaults.ctl.card 0" by VARX and "defaults.pcm.card 0" by VARY. The contents of FILE1 is the file being used to search for both text fields, and FILE2 is the output file. I tried using single quotes, double quotes, and a mixture of both, and no go whatsoever. So my question... What is the proper way of searching for text within a file and replacing with a variable?

View 5 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

General :: Shell Scripting - For Each File In Directory

May 2, 2011

I am working on some homework, however i am not here to be spoon fed. I am trying to get the numerical modification date of each file in a folder. Ie lets say there is a file called bob and it was modified 2006-11-23. i want to get it into a variable as 20061123.

Now i currently have this code:

Code:

However for some reason my output is:

Quote:

See how the 2011 has been placed next to it? i ran it with -x and saw this:

Code:

However i do not know how to find a way around this?

View 11 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 :: 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 :: Shell Script To Copy Database Archivelogs Sequentially From One Directory To Another?

Jun 2, 2009

want to write a shell script to copy database archivelog files sequential from one directory to another directory within a server. I am hereby enclosing the sample archivelog file name. Archive log filename : log_0000118432_1.arc (Here number 0000118432 will be sequentially incremented by 1 for next filename). Here the catch is all Archivelogs must be copied to destination directory. Previously copied files should not be copied.

View 3 Replies View Related

Ubuntu :: Shell Script For Searching And Listing?

Aug 17, 2009

How could I give extension as a parameter and then script would take this given extension as parameter and would after that walk through the system and write these listed/ finded files directly to the file like $hostname.$extension.log. I was wondering something like this.

#!/bin/bash
EXTENSION=$1
HOSTNAME=$HOST
HOMEFOLDER=/home/

[code]....

View 1 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

General :: LS Hangs On Searching For Filename In Directory

Oct 19, 2010

I have a directory that has a large number of files, around 1.5 million at this point. If I go to the directory and type in "ls filename" for a filename that I know exists, ls just hangs. I have let it run for over 20 minutes and it never does anything. Up until yesterday the directory was working fine through samba serving up files, but now it doesn't return anything. How to proceed from here?

View 7 Replies View Related

Programming :: Searching For Video Or Screen Cast Which Shows Device Driver Programming?

May 30, 2010

I did searched you tube but my results were not great.I have 2 books on KernelProgramming.I feel I need if some where I can get a video tutorial which can help me to understand how to develop a Linux Device driver that will be great.I had a look at Greg Kroah Hartmans video lecture of developing patches on ......I have been reading books and a lot of stuff.So I wish if I could get a video lecture that would be better

View 1 Replies View Related

Programming :: OpenCV Programming - Highgui.h: No Such File Or Directory?

Jul 1, 2010

I installed OpenCV and am trying the example programs. When I try to compile like in the tutorial it is not finding highgui.h.I have 64 bit Mint if that helps at all

View 3 Replies View Related

Programming :: Libmpi_f90.so.0: Cannot Open Shared Object File: No Such File Or Directory

Aug 6, 2010

I am running after compiling a program and I find that I get the following. How best can I avoid this as i cannot run the program. I have tried removing the offending package, although I cannot find it. I have also tried re-installing. I have also tried changing FC and F90 flags to avoid the MPI version.

error while loading shared libraries: libmpi_f90.so.0: cannot open shared object file: No such file or directory

View 1 Replies View Related

General :: Script To Copy Some Files With Ftp After Searching In The Directory?

Apr 20, 2011

I was trying to develop a script which needs to check the count of files on hourly basis and if it find any addition it has to sftp and send a email on the status with filenames and number of files copied via sftp. I will put it on cron to run every hour.

I'll use ls /abc|wc -l to count the no. of lines for the first time and from then whenever a new file will be inserted it'll copy that file to another location or I'll take the date of the files and whichever is having a new date that will be copied to another location.

View 7 Replies View Related

General :: Recursive Searching Files In Directory Matching Given Name?

Apr 16, 2010

I am writing a shell script that finds all files named <myFile> in a directory <dir> or any of its subdirectories, recursively. I also need to take care of symbolic links that may form cycles, to avoid infinite loops. I am not supposed to use find command for the same

I started writing the code but got stuck. I thought using recursion may be a smart way, but its not working.

Code:
#!/bin/sh
findFiles()
{
thisDIR=$1
#cd $thisDIR
code....

View 5 Replies View Related

General :: Searching A Directory And Pulling Out Filenames With A Certain Pattern?

May 17, 2010

I would like to search a specific directory and pull out filenames that have this pattern: "_bsc_" Then I want to do some processing and move the file to another directory

View 5 Replies View Related

Programming :: Make A Folder For Each File In A Directory Then Move The File Into It

Nov 29, 2010

Initially I thought - use a for loop with ls in it:

Code:

However this causes lots of problems (folders have extensions, I have duplicate folders, the names with spaces create a folder for each element of the name).

The contents of the folder is basically movies (some with subtitles). Some of the names have things like (original) or CD1 CD2 in them.

View 15 Replies View Related

Programming :: Read A Value From A File In Shell Script?

Mar 12, 2010

So my firefox's profile.ini file looks like this:less .mozilla/firefox/profiles.ini

Code:
[General]
StartWithLastProfile=1

[code]...

View 9 Replies View Related

Programming :: Unable To Execute A 4GE File In Ksh Shell ?

Apr 7, 2010

I am trying to execute a 4GE file using command something like this "/usr/bin/ksh path of the file with some arguments " ex: /usr/bin/ksh /home/abc.4ge S "./xyz" . I am able to execute the 4GE without this "/usr/bin/ksh" specifying in the command which basically runs in ksh shell itself. But when i try to run it exclusively using the path of the shell it gives me an error something like this "/usr/bin/ksh: /home/abc.4ge: cannot execute". I did check the permissions and all the file has execute permission.

View 7 Replies View Related

General :: Searching A Specific Directory For Files Containing A Text String?

Nov 20, 2010

I am a member of a group which has written a program whose source code is being held in a specific directory (~cs252/Assignments/basicAsst/project) and we want to go through and change the parameters for the function "sequentialInsert." My job is to find all occurances of the function call to "sequentialInsert" and to also list the files from where the code came from. Also, I have to be in the commandsAsst directory when I do this. I have tried grep and find combined together, and I am at a lost.

View 1 Replies View Related

Programming :: Iterate The Content Of A File In The Shell Script?

May 29, 2010

i need to check group of URLs and there https requests from browser. Recently i got some command line web browsers to know the HTTPS status of the URL like curl, wget etc... Now all of i need to do is write a shell script. I will put all my URLs in a text file and my shell script should read each URL one by one and log the status along with the corresponding URL.

Sample output:

./myscript.sh url.txt
1. site - 200 OK

View 6 Replies View Related

Programming :: Copying A String From One File To Another In Shell Script?

Nov 10, 2010

Code:
function forcd
{

[code]...

View 2 Replies View Related

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 :: Shell Script - Redirect Output To File

Sep 6, 2010

I did a select on my db and now I need that this if consult return true for me salve the columns information in file. How I do this in Shell?!

View 3 Replies View Related

Programming :: Shell Script / How To Check File Size?

Jan 21, 2009

I have a file that's supposed to be growing in size 24/7. I want to check every 10 minutes via cron that it's actually growing. If not, send an email. Does anyone know how to write a script to do that?

View 3 Replies View Related

Programming :: Shell Script Replace A Line From A File?

Mar 4, 2010

I am beginner in this business of shell script and I have no idea how to do the following: I would like to replace the lines of my file that contains 'CFL=' by 'CFL=0.5'. Note that I want to replace the full line meaning

View 11 Replies View Related







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