Re: Editing Problem with bash script and sed

2017-11-18 Thread Rusi Mody
On Tuesday, November 14, 2017 at 9:50:06 PM UTC+5:30, Thomas George wrote: > The problem is editing long file names to shorten them. An example group > of file names is attached. > > The bash script copied from BashScripting is attached. This script works > perfectly with simple deletions, for e

Re: Editing Problem with bash script and sed RESOLVED

2017-11-14 Thread Thomas George
Thanks to all for very helpful responses. I have been trying to reinvent the wheel, rename does the job nicely and the perl regex's are more reliable. ^.*?-. allows removing the to the first - so repeated applications remove to the track numbers. The comments regarding the Trim_Line script were

Re: Editing Problem with bash script and sed

2017-11-14 Thread David Wright
On Tue 14 Nov 2017 at 11:07:47 (-0500), Thomas George wrote: > The problem is editing long file names to shorten them. > An example group of file names is attached. I thought someone might mention MC for doing this. The sequence of operations I would use here is: Select the files you want to ch

Re: Editing Problem with bash script and sed

2017-11-14 Thread Greg Wooledge
On Tue, Nov 14, 2017 at 07:37:34PM +0100, Thomas Schmitt wrote: > Hi, > > after reading man 1 "read", i have to add option "-r" to my proposal: > > ls -d * | grep "$1" | while read -r filename That fixes one problem, but there are plenty more still unfixed. If the user input ("$1") is to be t

Re: Editing Problem with bash script and sed

2017-11-14 Thread Greg Wooledge
On Tue, Nov 14, 2017 at 07:21:55PM +0100, Thomas Schmitt wrote: > ls -d * | grep "$1" | while read filename Eww. No. That code is broken in multiple ways. > n=$(echo "$fname" | sed -e s/"$1"//) > > Regrettably i found no way to make this safe against newlines in filenames.

Re: Editing Problem with bash script and sed

2017-11-14 Thread Thomas Schmitt
Hi, after reading man 1 "read", i have to add option "-r" to my proposal: ls -d * | grep "$1" | while read -r filename Have a nice day :) Thomas

Re: Editing Problem with bash script and sed

2017-11-14 Thread Thomas Schmitt
Hi, i see at least one problem in Trim_Line.sh : It uses "$1" as shell parser input and as sed regular expression. With "S.*-" as "$1", the meaning differs in both contexts. The shell parser input of for filename in *$1* will look for files with a text snippet "S.". The expression in s/$1

Re: Editing Problem with bash script and sed

2017-11-14 Thread Roberto C . Sánchez
On Tue, Nov 14, 2017 at 11:07:47AM -0500, Thomas George wrote: > > After experimenting with regular expressions with sed I found ls | sed -e > s/S.*-// reduced the file names in File.txt to just the names of the Carols > as shown in sed.txt. Used like this sed leaves the original file unchanged. >

Editing Problem with bash script and sed

2017-11-14 Thread Thomas George
The problem is editing long file names to shorten them. An example group of file names is attached. The bash script copied from BashScripting is attached. This script works perfectly with simple deletions, for example TrimLine.sh "College" "" will remove College from each line in File.txt. A