Replace part of folder(s)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace part of folder(s)
# 8  
Old 04-29-2013
Quote:
Originally Posted by pasc
I'm sorry to tell you this, however it seems as if none of the above work.
Your feedback is utterly useless. It provides absolutely no useful information to those trying to help you.

For starters, tell us what shell and operating system you are using. Then copy/paste the code of each suggestion exactly as you ran it and any error messages that the system generated.

Regards,
Alister
# 9  
Old 04-29-2013
I understand that this isn' the most productive feedback, however I'm kind unsure what else to post.

What else do I have to do than change into said dir and executing the command to rename ".x.deb" folders to just norma names ?

I use a shell developed for jailbroken iOS devices. (version ?)
I ran each and every command exactly as posted.
There were no error messages after executing said commands.
Sed is available on said platform.
# 10  
Old 04-29-2013
In your initial post you state that you have a script which generates folder names, but none of the suggestions provided will read those names. So it is not clear how you're using those suggestions.

Unless stderr has been redirected in your environment (which would mean you would never see error messages), my guess is that the code is probably running correctly but there are no directories within the current working directory that fulfill the name criterion.

If you want to use any of the solutions provided in this thread, you must run the code from that directory's parent.

If you would like to use the folder names provided by your script, then post a sample of the data generated by your script, so that we are not forced to make assumptions (such as, one line per absolute pathname).

If you are not able to identify your shell, then post the script you're using to generate the names. At the very least, that script's code will inform us somewhat (is it a csh or bourne sh derivative, etc).

Regards,
Alister

Last edited by alister; 04-29-2013 at 02:28 PM..
# 11  
Old 04-29-2013
Try one of the following, depending on if test.x.deb or testx.deb input names, and let us know what happens. You will set value of DIR in the script.

-----------------------------------

Variation if test.x.deb form:
Code:
$ cat test.sh
DIR=/tmp/test
echo Before:
file $DIR/*
for old_sub in $DIR/*.x.deb; do
  if [ -d "$old_sub" ]; then
    new_sub=$(echo "$old_sub" | sed "s/\.x\.deb$//")
    mv "$old_sub" "$new_sub"
  fi
done
echo After:
file $DIR/*

Code:
$ ./test.sh
Before:
/tmp/test/subdir-1.x.deb: directory
/tmp/test/subdir-2.x.deb: directory
After:
/tmp/test/subdir-1: directory
/tmp/test/subdir-2: directory

-----------------------------------

Variation if testx.deb form:
Code:
$ cat test.sh
DIR=/tmp/test
echo Before:
file $DIR/*
for old_sub in $DIR/*x.deb; do
  if [ -d "$old_sub" ]; then
    new_sub=$(echo "$old_sub" | sed "s/x\.deb$//")
    mv "$old_sub" "$new_sub"
  fi
done
echo After:
file $DIR/*

Code:
$ ./test.sh
Before:
/tmp/test/subdir-1x.deb: directory
/tmp/test/subdir-2x.deb: directory
After:
/tmp/test/subdir-1: directory
/tmp/test/subdir-2: directory

# 12  
Old 05-02-2013
Well, I tried all of your scripts.

I created a "test.x.deb" directory by hand just to make sure.

Changed the dir to /var/mobile/Media/Downloads

This is the result (didn't change the name from test.x.deb to test btw):

Code:
login as: root
root@192.168.1.74's password:
Pascals-iPhone:~ root# cd /var/mobile/Media/Downloads
Pascals-iPhone:/var/mobile/Media/Downloads root# ls
BackupScript.deb  test.deb.x/  test.sh*
Pascals-iPhone:/var/mobile/Media/Downloads root# ./test.sh
./test.sh: line 1: $: command not found
Before:
/var/mobile/Media/Downloads/BackupScript.deb: Debian binary package (format 2.0)
/var/mobile/Media/Downloads/test.deb.x:       directory
/var/mobile/Media/Downloads/test.sh:          ASCII text
After:
/var/mobile/Media/Downloads/BackupScript.deb: Debian binary package (format 2.0)
/var/mobile/Media/Downloads/test.deb.x:       directory
/var/mobile/Media/Downloads/test.sh:          ASCII text
./test.sh: line 14: $: command not found
./test.sh: line 15: Before:: command not found
./test.sh: line 16: /tmp/test/subdir-1.x.deb:: No such file or directory
./test.sh: line 17: /tmp/test/subdir-2.x.deb:: No such file or directory
./test.sh: line 18: After:: command not found
./test.sh: line 19: /tmp/test/subdir-1:: No such file or directory
./test.sh: line 20: /tmp/test/subdir-2:: No such file or directory
./test.sh: line 22: $: command not found
Before:
/var/mobile/Media/Downloads/BackupScript.deb: Debian binary package (format 2.0)
/var/mobile/Media/Downloads/test.deb.x:       directory
/var/mobile/Media/Downloads/test.sh:          ASCII text
After:
/var/mobile/Media/Downloads/BackupScript.deb: Debian binary package (format 2.0)
/var/mobile/Media/Downloads/test.deb.x:       directory
/var/mobile/Media/Downloads/test.sh:          ASCII text
./test.sh: line 35: $: command not found
./test.sh: line 36: Before:: command not found
./test.sh: line 37: /tmp/test/subdir-1x.deb:: No such file or directory
./test.sh: line 38: /tmp/test/subdir-2x.deb:: No such file or directory
./test.sh: line 39: After:: command not found
./test.sh: line 40: /tmp/test/subdir-1:: No such file or directory
./test.sh: line 41: /tmp/test/subdir-2:: No such file or directory
Pascals-iPhone:/var/mobile/Media/Downloads root#

# 13  
Old 05-02-2013
To be clear, here is all you need to put in the script:
Code:
DIR=/tmp/test
echo Before:
file $DIR/*
for old_sub in $DIR/*.x.deb; do
  if [ -d "$old_sub" ]; then
    new_sub=$(echo "$old_sub" | sed "s/\.x\.deb$//")
    mv "$old_sub" "$new_sub"
  fi
done
echo After:
file $DIR/*

Is that what you had? Does it work with that content?

$ cat test.sh is not part of the script. The $ is the command prompt and cat test.sh is the command I entered to show the script.

./test.sh: line 1: $: command not found error message suggests you included $ cat test.sh in the shell script.

./test.sh: line 35: $: command not found suggests you have added many more lines to the script than needed, a lot of extraneous matter.

If it's still not working, post the exact script you used. The way you posted the error messages was great. Smilie
# 14  
Old 05-04-2013
This is the script tested:

Code:
DIR=/var/mobile/Media/Downloads
echo Before:
file $DIR/*
for old_sub in $DIR/*.x.deb; do
  if [ -d "$old_sub" ]; then
    new_sub=$(echo "$old_sub" | sed "s/\.x\.deb$//")
    mv "$old_sub" "$new_sub"
  fi
done
echo After:
file $DIR/*

And this is the result (as you can see, it did sadly not work this time either)
Code:
login as: root
root@192.168.1.74's password:
Pascals-iPhone:~ root# cd /var/mobile/Media/Downloads
Pascals-iPhone:/var/mobile/Media/Downloads root# ls
CleanUP.deb  CleanUP.deb.x/  test.sh*
Pascals-iPhone:/var/mobile/Media/Downloads root# ./test.sh
Before:
/var/mobile/Media/Downloads/CleanUP.deb:   Debian binary package (format 2.0)
/var/mobile/Media/Downloads/CleanUP.deb.x: directory
/var/mobile/Media/Downloads/test.sh:       ASCII text
After:
/var/mobile/Media/Downloads/CleanUP.deb:   Debian binary package (format 2.0)
/var/mobile/Media/Downloads/CleanUP.deb.x: directory
/var/mobile/Media/Downloads/test.sh:       ASCII text
Pascals-iPhone:/var/mobile/Media/Downloads root#
Pascals-iPhone:/var/mobile/Media/Downloads root# ls
CleanUP.deb  CleanUP.deb.x/  test.sh*

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace part of string?

Hi Gurus, I need to replace part of string in file, the string format is below: I can use ABCD to find string, then replace values after "=" sign ABCD_XXX=value ABCD_YYY=value after replace ABCD_XXX=new_value ABCD_YYY=new_value my OS is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ... (9 Replies)
Discussion started by: green_k
9 Replies

2. Red Hat

Identify the folder is part of which mount point

Dear, I am using Redhat 6.6 . How to identify a given directory is part of which mount point. (2 Replies)
Discussion started by: aneesha
2 Replies

3. Shell Programming and Scripting

awk to replace part of a column

dear all, I'm trying to use Awk to eliminate the last two characters from the first column in a file. This two characters are "-1" and I need to eliminate them from each row that I have in the files. The files have two columns and look like: ID_090-1 2 ID_3787-1 4 ID_0098-1 1 ID_12-1 4 I... (4 Replies)
Discussion started by: gabrysfe
4 Replies

4. Shell Programming and Scripting

SED - replace only on part of the string

Hello there, I need some help. I have a file containing this : $ cat file PARM1=(VAL11),PARM2=(VAL21,VAL22,VAL23),PARM3=(VAL31),PARM4=(VAL41,VAL42) and I need to replace all the ',' by '|' but only those which are between brackets. Output would be :... (10 Replies)
Discussion started by: Sephiburp
10 Replies

5. Shell Programming and Scripting

Replace a part of the string

Hi I need to Replace a part of string in between one complete string. For e.g.. in the file the value is as: jobnm_$code_xyz_001 In script we are having a variable code=$3, where $3=ab final output should be jobnm_ab_xyz_001. But it is not working. Your help will be... (1 Reply)
Discussion started by: vee_789
1 Replies

6. Shell Programming and Scripting

replace part of text of a line

Gurus, You know, I believe you do:-), the comnand uname -r give you the kernel version: serverA:~# uname -r 2.6.26-1-xen-amd64So, I want to replace this output inside in the line below that is inside the file: kernel = '/boot/vmlinuz-2.6.26-1-xen-amd64'Suppose, you move this file to ther... (2 Replies)
Discussion started by: iga3725
2 Replies

7. Shell Programming and Scripting

Suggestion to replace a part of script

I have the part of script: if ; then make_command="make -f $temp_file" print $make_command; err_file="${sym_objdir}error.log" $make_command 2>$err_file; cat $err_file; ] && ] && exit 1; exit 0 fi ... (5 Replies)
Discussion started by: Ajay_84
5 Replies

8. UNIX for Dummies Questions & Answers

regarding replace a part of a string

hi all. i have a file name like abcd_vbnh.a_p i have to copy it as abcd_vbnh.a every time... in unix not in perl please (7 Replies)
Discussion started by: madhu_aqua14
7 Replies

9. Shell Programming and Scripting

Find and replace a part of the word in Shell

I have a csv file in which there are numbers like 078976/9XXX 098754/8XXX I want to replace the XXX with null. I want to know the command/code to do this. I know how to replace the whole word/number. But don't know how to replace a part of it. Thanks in advance, Mihir (3 Replies)
Discussion started by: mihirk
3 Replies

10. Shell Programming and Scripting

using sed to replace a part of string

Hi, I have files that are named front1.txt to front999.txt. They are all in the same directory. To change "front" to "back", I am doing something like this. for file in *.txt; do new=`echo $file | sed 's/^**/back/g'` mv $file $new done My problem is what if files are named... (6 Replies)
Discussion started by: csejl
6 Replies
Login or Register to Ask a Question