Results 1 to 4 of 4
Hello,
I have recently moved to Kubuntu and I need to convert some win command.com script to linux script.
The WIN script is:
## start code ##
@echo off
for ...
- 09-08-2007 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 1
Help with Automated file search and replacement.
Hello,
I have recently moved to Kubuntu and I need to convert some win command.com script to linux script.
The WIN script is:
## start code ##
@echo off
for /R %%x in (.) do if exist %%x\title. (
set path=%%x
set var=!path:~7,-10!
echo !var! > !path!\title
)
##end code##
The code starts in some directory and recursively goes through the directory putting the path of each subdirectory into the '%%x' variable the if statement tests to see if the subdirectory has a file called title in it, if yes the contents of the variable '%%x' are set to the string 'path'. A subset of the contents of the 'path' variable are put into the 'var' variable. The contents of the 'var' variable are then echoed into the 'title' file of the subdirectory in question. Note. before you ask the in windows the '%%x' variable can't be manipulate as a string hence the dump into the 'path' variable.
Basically I am very new to linux script and would like some pointers to help me convert this code quickly as I need it very quickly.
many thanks
Mark
- 09-08-2007 #2
Well take a look at a function I once wrote as a novelty exercise that emulates the find command with nothing but shell built-ins:
So, the algorithm for doing this is in there, except that prints out all files in each directory. When you're in each directory instead of echoing the filenames, you will doCode:#!/bin/bash function myfind { for FILE in *; do if [ $FILE = '*' ]; then continue elif [ -d $FILE ]; then echo ${PWD}\/$FILE pushd $FILE > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "Permission to enter $FILE denied." continue fi myfind else echo ${PWD}\/$FILE continue fi popd >/dev/null 2>&1 done } myfind
If you have questions about what this code does, just reply to the thread.Code:if [ -e title ]; then dirs +0 > title fi
- 09-08-2007 #3Linux User
- Join Date
- Aug 2006
- Posts
- 458
you can use find .
you can pipe out the results for further processing.Code:find /yourpath -type f -name "title" -print
- 09-08-2007 #4
Yea, that would actually probably be easier to someone going from windows scripting to bash, I instantly just thought of that function I posted just cause I don't think anything else ever presented itself that had a practical use for it.


Reply With Quote