Full Discussion: SED inside while loop
Top Forums UNIX for Dummies Questions & Answers SED inside while loop Post 302370574 by paoie on Wednesday 11th of November 2009 10:52:28 PM
what i mean is i want to insert incrementing numbers in the varibles $VAR and $VAR2. But the code is making the sed command, which displays all the lines in the file test.csv, $lines number of times before it loops and repeats again.

that is why the result is

Code:
 
a,b,c,d,e,one1too1,f
a,b,c,d,e,one1too1,f
a,b,c,d,e,one1too1,f
 
a,b,c,d,e,one1too2,f
a,b,c,d,e,one1too2,f
a,b,c,d,e,one1too2,f
 
a,b,c,d,e,one1too3,f
a,b,c,d,e,one1too3,f
a,b,c,d,e,one1too3,f
 
a,b,c,d,e,one1too4,f
a,b,c,d,e,one1too4,f
a,b,c,d,e,one1too4,f

when i tried your sugesstion:

the result looks like this:

Code:
 
1
a,b,c,d,e,one1too1,f
a,b,c,d,e,one1too1,f
a,b,c,d,e,one1too1,f
2
a,b,c,d,e,one1too2,f
a,b,c,d,e,one1too2,f
a,b,c,d,e,one1too2,f
3
a,b,c,d,e,one1too3,f
a,b,c,d,e,one1too3,f
a,b,c,d,e,one1too3,f
4
a,b,c,d,e,one1too4,f
a,b,c,d,e,one1too4,f
a,b,c,d,e,one1too4,f
1
2
3
4


what i want the result to be is:

Code:
 
a,b,c,d,e,one1too1,f
a,b,c,d,e,one2too2,f
a,b,c,d,e,one3too3,f
a,b,c,d,e,one4too4,f

The word "one" and "too" are fixed and only the numbers (e.g from 1 to 4) should be incrementing.
 
Test Your Knowledge in Computers #665
Difficulty: Easy
In 2000, Microsoft cofounder Bill Gates relinquished his role as CEO of Microsoft to Steve Baltimore.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

remsh inside of while loop

I have a space delimited file containing: hostname OracleSID connectstring I want to loop through the file and execute remsh to check the database processes. cat $filename | while read HOST SID CONNECT do { result=`remsh $HOST "ps -ef | grep pmon_${SID}$| grep -v grep"` if ........ (1 Reply)
Discussion started by: joettacm
1 Replies

2. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

3. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

4. Shell Programming and Scripting

Using 'su' inside a loop

Hi, I am using su within a for loop. As you might expect, it prompts for password during each loop execution. Here is my piece of code: for i in $LIST do if then DATABASE=`echo $i | awk -F "|" '{ print $1 }'` USER_ID=`echo $i | awk -F "|" '{ print $2 }'` su - apstage -c... (1 Reply)
Discussion started by: sugan
1 Replies

5. Shell Programming and Scripting

Need help using sed inside the loop.

Hi, i have written a script. it collects data based on the sql queries executed by it. i have multiple output files. after the output file is made i need to do some cosmetic changes in the files and then store them. i am unable to use sed conditions inside the loop. see below code for... (3 Replies)
Discussion started by: dazdseg
3 Replies

6. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

7. Shell Programming and Scripting

sed inside sed for replacing string

My need is : Want to change docBase="/something/something/something" to docBase="/only/this/path/for/all/files" I have some (about 250 files)xml files. In FileOne it contains <Context path="/PPP" displayName="PPP" docBase="/home/me/documents" reloadable="true" crossContext="true">... (1 Reply)
Discussion started by: linuxadmin
1 Replies

8. Shell Programming and Scripting

help using EOF inside a for loop

I'm having problems with this example: #!/bin/bash for i in server1 server2 server3 do ssh $i <<EOF >> logfile.txt dat1=`date '+%m/%d/%y'` hst=`hostname` df -Ph | awk -v OFS=',' -v dat="$dat1,$hst" ' {print dat,$1,$6,$3,$4 } ' exit EOF done I'm... (1 Reply)
Discussion started by: kuliksco
1 Replies

9. Shell Programming and Scripting

If inside If loop

Hi All, Below is the very simple code snippet but it si giving me syntax error #!/bin/bash #To ensure If JMS directory exists or not ServerName=$(hostname) #To ensure If JMS directory exists or not echo $ServerName if ; then echo "Inside First If" if ; then echo 'JMS... (4 Replies)
Discussion started by: sharsour
4 Replies

10. UNIX for Dummies Questions & Answers

Write a while loop inside for loop?

I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off.... I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Discussion started by: xxhieixx
3 Replies
while(n)						       Tcl Built-In Commands							  while(n)

__________________________________________________________________________________________________________________________________________________

NAME
while - Execute script repeatedly as long as a condition is met SYNOPSIS
while test body _________________________________________________________________ DESCRIPTION
The while command evaluates test as an expression (in the same way that expr evaluates its argument). The value of the expression must a proper boolean value; if it is a true value then body is executed by passing it to the Tcl interpreter. Once body has been executed then test is evaluated again, and the process repeats until eventually test evaluates to a false boolean value. Continue commands may be exe- cuted inside body to terminate the current iteration of the loop, and break commands may be executed inside body to cause immediate termi- nation of the while command. The while command always returns an empty string. Note: test should almost always be enclosed in braces. If not, variable substitutions will be made before the while command starts execut- ing, which means that variable changes made by the loop body will not be considered in the expression. This is likely to result in an infinite loop. If test is enclosed in braces, variable substitutions are delayed until the expression is evaluated (before each loop iter- ation), so changes in the variables will be visible. For an example, try the following script with and without the braces around $x<10: set x 0 while {$x<10} { puts "x is $x" incr x } SEE ALSO
break(n), continue(n), for(n), foreach(n) KEYWORDS
boolean value, loop, test, while Tcl while(n)

Featured Tech Videos

All times are GMT -4. The time now is 03:59 PM.
Unix & Linux Forums Content Copyright 1993-2020. All Rights Reserved.
Privacy Policy