Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #188982
| From | "Thomas Schmitt" <scdbackup@gmx.net> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: Editing Problem with bash script and sed |
| Date | 2017-11-14 19:30 +0100 |
| Message-ID | <uLO89-7my-1@gated-at.bofh.it> (permalink) |
| References | <uLM6l-5Xj-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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//
will not insist in seeing the "." after "S". It rather understands the "."
as instruction to match any character.
Looking at File.txt, i'd say "St.*-" could match the "St. John's College
Choir, Cambridge -" files in both interpretations.
In general, sed goes better with grep than with the shell parser.
Try
ls -d * | grep "$1" | while read filename
do
...
n=$(echo "$fname" | sed -e s/"$1"//)
Regrettably i found no way to make this safe against newlines in filenames.
I'd do it in C language if such names were to be expected.
Have a nice day :)
Thomas
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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