BSD Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsBSD Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 25th, 2003, 09:08 PM
ktoz ktoz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 440 ktoz User rank is Sergeant (500 - 2000 Reputation Level)ktoz User rank is Sergeant (500 - 2000 Reputation Level)ktoz User rank is Sergeant (500 - 2000 Reputation Level)ktoz User rank is Sergeant (500 - 2000 Reputation Level)ktoz User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 52 m 3 sec
Reputation Power: 25
Can sed operate on a loop variable?

I'm sure this is an easy one but I can't seem to get it working. Given the following:

for oldName in `ls *.JPG` ;do
newName=<confusion here. how to make sed perform 's/.JPG/_thumb.JPG/g' operation on $oldName>
done

Could someone show me how to make this work?

Thanks

Ken

Last edited by ktoz : May 26th, 2003 at 01:20 PM.

Reply With Quote
  #2  
Old May 26th, 2003, 03:54 PM
ktoz ktoz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 440 ktoz User rank is Sergeant (500 - 2000 Reputation Level)ktoz User rank is Sergeant (500 - 2000 Reputation Level)ktoz User rank is Sergeant (500 - 2000 Reputation Level)ktoz User rank is Sergeant (500 - 2000 Reputation Level)ktoz User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 52 m 3 sec
Reputation Power: 25
Solved

Well that was fun...

Here's the solution I came up with to duplicate a group of files, selected by pattern into the current working directory. Hope this saves someone else some time.

#!/bin/sh

# change values of following two variables to whatever you want
oldPattern=".JPG"
newPattern="_copy.JPG"

for tmp in `ls *.$oldPattern | sed "s/$oldPattern//g"`; do
# create the new file
touch $tmp$newPattern

# copy contents of old file into new file
cp $tmp$oldPattern $tmp$newPattern
done

Ken

Reply With Quote
  #3  
Old June 3rd, 2003, 09:56 AM
zakj zakj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 52 zakj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 41 sec
Reputation Power: 6
Code:
for i in *.JPG; do
  cp $i ${i%.JPG}_thumb.JPG
done

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsBSD Help > using egrep to rearrange file names


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway