Change argument in a for loop

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Change argument in a for loop
# 1  
Old 11-01-2013
Question Change argument in a for loop

In a "for i in *FD.CPY do" loop, I need to change .CPY to .layout so the executed command would be
reclay blahFD.CPY >blahFD.layout

What do I need to do to modify a copy of i to use after the > symbol?

# 2  
Old 11-01-2013
reclay $i > ${i%CPY}layout

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 11-01-2013
reclay "$i" > "${i%.CPY}.layout"

It looks like bartus11 and I had similar thoughts and posted them at about the same time.

As long as none of the filenames matched by *.CPY contain any whitespace characters, both should do the same thing. If any of your filenames might contain spaces, tabs, or newlines, the quotes will make a huge difference. For the patterns CPY and .CPY, ${i%%pattern} and ${i%pattern} produce identical results.

Last edited by Don Cragun; 11-01-2013 at 05:06 PM.. Reason: Add comparison of proposals.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 11-04-2013
I was not able to get that substitution to fly but found a way around it.

My question is that in its present form the script only processes the first file it finds in the parameter. If I give scriptname *FD.CPY , the script only processes the first file matching that description. If I put the above expression in the script instead of $1, it does it on everything (it's supposed to). How can I change it to work on (a) specified file(s) in the parameter?


for i in $1
suby="`echo $i |sed 's/CPY/CPy/'`"
subz="`echo $i |sed 's/CPY/CPz/'`"
sublay="`echo $i |sed 's/CPY/layout/'`"
sed "s/*>.*/ /" $i > $suby
reclay $suby > $subz
sed "s/CPy/CPY/" $subz > $sublay
rm $suby $subz

# 5  
Old 11-04-2013
for i in $1

for i in "$@"

This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 11-04-2013
Thanks, Don. It performed as advertised.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

2. Shell Programming and Scripting

Doing a loop to change a value in a file

Hi, I have an N number of files in a directory. I like to write a shell script that would make identical plots for each one of these files. The files have names such as: t00001.dat t00002.dat t00003.dat t00004.dat t00005.dat . . . t00040.dat i.e. the... (4 Replies)
Discussion started by: lost.identity
4 Replies

3. Shell Programming and Scripting

Change a field value in a loop

Hi guys, i have an executable file that contains several records and fields. One of the records has a variable filed that must be changed each time i want to execute the file. Would it be possible that i can use a loop to change the value of that field? Suppose that the field address is: Record... (5 Replies)
Discussion started by: saeed.soltani
5 Replies

4. Shell Programming and Scripting

Expect Scripting Loop Argument Desperately Needed!

I am trying to create an Expect script that does the following: 1) Telnets to an IP address and logs in with user ID and Password 2) Issue a CLI command to the server that will output data of which I am particularly interested in a DS1 clock 'Slips' value. I want to be able to keep issuing... (0 Replies)
Discussion started by: dwightlaidler
0 Replies

5. Shell Programming and Scripting

Variable name change in a loop

I need to do something like this:for I in var1 var2 var3 ; do $I = "Something calculated inside the loop" doneObviously it doesn't work...but is it possible doing that in other ways? Thanks in advance. (6 Replies)
Discussion started by: canduc17
6 Replies

6. UNIX for Dummies Questions & Answers

how to change argument of an script

Hello every one i have an script in sco unix 5.06 to take a long archive over MOD drive and this script contains many line to change destination to DVD anyone can help to me for change this script to take backup on DVD instead of MOD the attached script LzaModBed.engl (1 Reply)
Discussion started by: kaydream
1 Replies

7. UNIX for Dummies Questions & Answers

change if-else loop to while-do

Hello friends, i wrote a script which includes a couple of if-else loops but i have to change it to while-do loop as it is not allowed to use "break" in if-else loop in bash. #!/bin/bash -x NUM=`find . -name ufsdump_output1.txt | xargs egrep "End-of-tape detected"` if ; then echo "OK!"... (6 Replies)
Discussion started by: EAGL€
6 Replies

8. Shell Programming and Scripting

loop through file to change some data

Hi, I have a file with the following data -0.00000 0.00000 0.00000 F F F 0.00000 0.00000 0.80000 F F F 0.50000 0.50000 0.60000 F F F 0.50000 0.50000 0.20000 F F F -0.00000 0.00000 0.40000 F F F I would like to change the last 3 lines from F F F to T T T. I tried looping each line but don't... (5 Replies)
Discussion started by: princessotes
5 Replies

9. Shell Programming and Scripting

grabbing more than one argument in a loop

Hello all I hope someone can help me. I am trying to convert something I wrote in C to bash. But how do I go about reading more than one item at a time in a for loop? i have been using this format for the loops in the bash script i have been building. e.g. for word in `cat -s... (4 Replies)
Discussion started by: Intense4200
4 Replies

10. Shell Programming and Scripting

Argument passing using for or while loop

Hi All, My query is as below: Am basically writing a parser script. My input file has got some variables which are populated by the calling program. callig program: fun1("cat","dog","cow") input.* argument first argument second I want to write a script that should give me... (4 Replies)
Discussion started by: jisha
4 Replies
Login or Register to Ask a Question