Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #188989

Re: Editing Problem with bash script and sed RESOLVED

From Thomas George <lists@tomgeorge.info>
Newsgroups linux.debian.user
Subject Re: Editing Problem with bash script and sed RESOLVED
Date 2017-11-14 21:20 +0100
Message-ID <uLPQB-9k-1@gated-at.bofh.it> (permalink)
References <uLM6l-5Xj-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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 an education explaining why it did not work as 
expected.


On 11/14/2017 11:07 AM, 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 example TrimLine.sh 
> "College" "" will remove College from each line in File.txt.
>
> 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.
>
> Trim_Line.sh "S.*-" "" fails to actually change the file names. 
> Assuming Trim_Line.sh does not accept the regex as a pattern, I edited 
> it to replace the $1 in the sed command with the regex expression. 
> This does not work, the original file is left unchanged.  I also 
> tried  replacing $1 with ^.*- which also works with the test ls | sed 
> -e s/^.*-// but still the file names are unchanged.
>
> I would appreciate any help or comments.
>
> Tom George
>

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Editing Problem with bash script and sed Thomas George <lists@tomgeorge.info> - 2017-11-14 17:20 +0100
  Re: Editing Problem with bash script and sed Roberto C. Sánchez <roberto@debian.org> - 2017-11-14 17:30 +0100
  Re: Editing Problem with bash script and sed "Thomas Schmitt" <scdbackup@gmx.net> - 2017-11-14 19:30 +0100
    Re: Editing Problem with bash script and sed "Thomas Schmitt" <scdbackup@gmx.net> - 2017-11-14 19:40 +0100
      Re: Editing Problem with bash script and sed Greg Wooledge <wooledg@eeg.ccf.org> - 2017-11-14 19:50 +0100
    Re: Editing Problem with bash script and sed Greg Wooledge <wooledg@eeg.ccf.org> - 2017-11-14 19:50 +0100
  Re: Editing Problem with bash script and sed David Wright <deblis@lionunicorn.co.uk> - 2017-11-14 20:50 +0100
  Re: Editing Problem with bash script and sed RESOLVED Thomas George <lists@tomgeorge.info> - 2017-11-14 21:20 +0100
  Re: Editing Problem with bash script and sed Rusi Mody <rustompmody@gmail.com> - 2017-11-19 06:10 +0100

csiph-web