IBM developerWorks
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX 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 November 20th, 2003, 08:26 PM
tzeyik tzeyik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 22 tzeyik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to return argument of command line?

I want to change the href path in many files. So, i write a simple script and save it into a file to run it.

for i in filename1, filename2
do
sed 's/src=/src=..\/page\//' $i > change.tmp
cp -f change.tmp $i
done

so, in order to change some specific file, i hv to go into the file and change the filename manually.. I wish to make it more effective that it can return the argument of unix commandl line and run the program. so, i no need to hardcored the filename in the script.

eg. change a.html
# change is the script name, so, a.html will pass into the change file and run the script inside change the path of a.html.

anyone can give me some idea how to do it? Druuna, i hope u can see this message and teach me how to do..

thanks...

Reply With Quote
  #2  
Old November 21st, 2003, 09:08 AM
druuna druuna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 137 druuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 37 sec
Reputation Power: 0
I'm not certain that I understand the question.

This is what I think you want:

1) change href="whatever" to href="your-choice" in a specific file.
2) give the name of the file(s) to change as option to a script.

Another question:

What do the original scr="...." look like, or are they empty. I need to know this because of the regular expression that needs to be constructed for the sed statement.

Last edited by druuna : November 21st, 2003 at 10:52 AM.

Reply With Quote
  #3  
Old November 26th, 2003, 06:58 PM
tzeyik tzeyik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 22 tzeyik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
drunna, actually wat u understand is correct.

here is the situation, there are some files tat i need to change the file path for each files. So, i dun wan manually change it one by one. So, i wan to write some script and included all those file in tat script in order to run the process.

for the src question, ../page is go out for the current directory and get into another page directory! I test it, it is work properly.. so, no need to bother abt this question.

my question is there any shell script tat can retrieve or return the argument of the unix command?

Reply With Quote
  #4  
Old November 27th, 2003, 12:54 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
The command line arguments are passed to shell scripts via $1, $2, $3, ...; "$*" contains all of them.


#!/bin/sh
for i in $*; do ...

Second solution:
put them in a text file, say /tmp/files.txt
then use:
for i in `cat /tmp/files.txt`; do ...

Another one:
pipe the file to the script and make the script read from stdin:
cat /tmp/files.txt | script.sh
(or: script.sh < /tmp/files.txt)

while read filename; do...

hth,
M.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Last edited by M.Hirsch : November 27th, 2003 at 12:56 PM.

Reply With Quote
  #5  
Old November 27th, 2003, 08:01 PM
tzeyik tzeyik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 22 tzeyik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the so many alternative solution..

I try all of those solution. The first one work perfectly.. But the second and third solution is not working.

For the second solution, i put the file.txt and the script.sh into same directory. some error msg appear like this : "cannot find and open file cat"
for i in 'cat file.txt'
do
sed 's/src=/src=..\/page\//' $i > change.tmp
cp -f change.tmp $i
done

for the third solution, it appear msg like "file.txt : this is not an identifier"
while read file.txt
do
sed 's/src=/src=..\/page\//' $i > change.tmp
cp -f change.tmp $i
done

May i noe y this kinds of errors appear? Thanks~

Reply With Quote
  #6  
Old November 28th, 2003, 01:17 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
#2 failed because this is supposed to be backticks, not single quotes. ` not '
But on second thought, don't use it. I guess it will fail when filenames contain spaces (untested).

#3 was a little misleading, sorry, I should have said some more words.
"filename" was the variable name here.
So:
script.sh:
Code:
#!/bin/sh
while read i
do
sed 's/src=/src=..\/page\//' "$i" > change.tmp
cp -f change.tmp "$i"
done

And then: ./script.sh < ./files.txt
Also add the quotes around "$i" to deal with spaces in filenames.

hth,
M.

Reply With Quote
  #7  
Old November 30th, 2003, 07:22 PM
tzeyik tzeyik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 22 tzeyik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks M.Hirsch~ I test it again with ur instruction. All is work perfectly~
Thanks to drunna also, u help me a lots too~

I am very glad found this forum with so many helpful frens here~ Have a nice day, guys!
Thanks a lots!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > How to return argument of command line?


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 5 hosted by Hostway