Sponsored Content
Full Discussion: Use of For loop with Space
Top Forums UNIX for Dummies Questions & Answers Use of For loop with Space Post 302319972 by peter35james on Tuesday 26th of May 2009 05:23:24 PM
Old 05-26-2009
Use of For loop with Space

Hi,

I am trying to query the database to get the list of portfolio and for each portfolio, I am using the for loop, but the problem is some of the portfolio is having the spaces.

The Code

PORT=`${EFG_ISQL} -b <<-!
set nocount on
use ${EFG_DB}
go
select portId from PORTFOLIO
go
!`

echo $PORT

for Portfolio in $PORT
do
........................
done

When the portfolio is having spaces, the for loop is run for each word.

I tried using the IFS and changed the code to

PORT=`${EFG_ISQL} -b <<-!
set nocount on
use ${EFG_DB}
go
select portId from PORTFOLIO
go
!`
echo $PORT

spaces=IFS
IFS="
"
for Portfolio in $PORT
do
echo $Portfolio
.....
done

but now it is printing each string with a fixed lenght and appending the space after the string.

Can you please help me.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing space delimited line in var with loop?

I have a script that converts a file into an html table. This script works fine for a 1 column table. However, I'm trying to do this for a multi-column table. My input file will look something like this: a b c d e f g h i My script basically works by taking in each line and putting that... (2 Replies)
Discussion started by: eltinator
2 Replies

2. Shell Programming and Scripting

how to protect white space in for loop

Hi All, I know there's a really simple answer to this but I just can't think of it :) I'm processing a file which has lines containing white space i.e. And I want to perform some awk on each line but when I do the following: for US in $( cat /tmp/unique-strings.tmp | sed 's/\/\\]/g'... (6 Replies)
Discussion started by: pondlife
6 Replies

3. Shell Programming and Scripting

Moving files with space, in for loop

Hi All I need to put a bunch of specific files in a directory (with loads of other files), into a tar archive. The best way I thought of doing this was putting the filenames into a file, reading them line by line in a for loop, and then adding them to a tar acrhive. However the filenames have... (6 Replies)
Discussion started by: saabir
6 Replies

4. Shell Programming and Scripting

Problem if parameter has space in it using loop

for cmdopts in $*;do case $cmdopts in -mode) mode="$2";shift 2 ;; -server) server="$2";shift 2 ;; -Id) Id="$2";shift 2 ;; -passwd) passwd="$2";shift 2 ;; -rmtDir) rmtDir="$2";shift 2 ;; -lcDir) ... (9 Replies)
Discussion started by: pinnacle
9 Replies

5. Shell Programming and Scripting

Escape space in for loop

I have a file with the following contents # more hello.txt man hello man whereru The shell script i have tries to echo the contents of the file hello.txt for i in `cat hello.txt` do echo $i done but the output i am getting is taking the space as a new line.. #... (3 Replies)
Discussion started by: Tuxidow
3 Replies

6. Shell Programming and Scripting

escape space characters in loop from file

Hi Everyone! I want to build sql inserts from a list of countries/regions saved in a file. The list looks like this: United Kingdom Czech Republic ... The script I run is: while read i; do var=`expr $var + 1`; echo "INSERT INTO calltypes VALUES($var, '$i','$i');" >>... (5 Replies)
Discussion started by: linuca
5 Replies

7. Shell Programming and Scripting

How to loop through space separated values?

How do I loop thru space separated values in a variable? I hate to use very complicated counter increment logic for this kind of simple problem. Expected result(using ksh) $>echo "aaa bbbb cccc" | <looping code here> var=aaa var=bbbb var=cccc $>echo "aaa bbbb cccc" | while IFS=" "... (12 Replies)
Discussion started by: kchinnam
12 Replies

8. Shell Programming and Scripting

Unable to read the first space of a record in while loop

I have a loop like while read i do echo "$i" . . . done < tms.txt The tms.txt contians data like 2008-02-03 00:00:00 <space>00:00:00 . . . 2010-02-03 10:54:32 (2 Replies)
Discussion started by: machomaddy
2 Replies

9. Shell Programming and Scripting

Need Help on For Loop to pass space separated value as one value

Hi, I am having a file say list1 with a output like below jun 12 18:23 may 20 18:23 Now i want to pass the above two values into for loop,I have written a script like this. #!/bin/bash a=`cat list1` for i in $a do echo "HI $i" done expected output: HI jun 12 18:23 (3 Replies)
Discussion started by: sumanthupar
3 Replies

10. UNIX for Beginners Questions & Answers

For loop with space in file name

Hi All I have a source file named ABC-20150613 to 20150613.zip. I was trying to execute the below command on this source file, but its telling file is not available in that path and giving me some random file names. ls -ltr| for z in ABC-????????*to*????????*.zip do unzip $z -d done I... (5 Replies)
Discussion started by: ginrkf
5 Replies
BeanCounter(3pm)					User Contributed Perl Documentation					  BeanCounter(3pm)

NAME
Finance::BeanCounter - Module for stock portfolio performance functions. SYNOPSIS
use Finance::BeanCounter; DESCRIPTION
Finance::BeanCounter provides functions to download, store and analyse stock market data. Downloads are available of current (or rather: 15 or 20 minute-delayed) price and company data as well as of historical price data. Both forms can be stored in an SQL database (for which we currently default to PostgreSQL though MySQL is supported as well; furthermore any database reachable by means of an ODBC connection should work). Analysis currently consists of performance and risk analysis. Performance reports comprise a profit-and-loss (or 'p/l' in the lingo) report which can be run over arbitrary time intervals such as "--prevdate 'friday six months ago' --date 'yesterday'" -- in essence, whatever the wonderful Date::Manip module understands -- as well as dayendreport which defaults to changes in the last trading day. A risk report show parametric and non-parametric value-at-risk (VaR) estimates. Most available functionality is also provided in the reference implementation beancounter, a convenient command-line script. The API might change and evolve over time. The low version number really means to say that the code is not in its final form yet, but it has been in use for well over four years. More documentation is in the Perl source code. DATABASE LAYOUT
The easiest way to see the table design is to look at the content of the setup_beancounter script. It creates the five tables stockinfo, stockprices, fxprices, portfolio and indices. Note also that is supports the creation of database for both PostgreSQL and MySQL. THE STOCKINFO TABLE The stockinfo table contains general (non-price) information and is index by symbol: symbol varchar(12) not null, name varchar(64) not null, exchange varchar(16) not null, capitalisation float4, low_52weeks float4, high_52weeks float4, earnings float4, dividend float4, p_e_ratio float4, avg_volume int4 This table is updated by overwriting the previous content. THE STOCKPRICES TABLE The stockprices table contains (daily) price and volume information. It is indexed by both date and symbol: symbol varchar(12) not null, date date, previous_close float4, day_open float4, day_low float4, day_high float4, day_close float4, day_change float4, bid float4, ask float4, volume int4 During updates, information is appended to this table. THE FXPRICES TABLE The fxprices table contains (daily) foreign exchange rates. It can be used to calculate home market values of foreign stocks: currency varchar(12) not null, date date, previous_close float4, day_open float4, day_low float4, day_high float4, day_close float4, day_change float4 Similar to the stockprices table, it is index on date and symbol. THE STOCKPORTFOLIO TABLE The portfolio table contains contains the holdings information: symbol varchar(16) not null, shares float4, currency varchar(12), type varchar(16), owner varchar(16), cost float(4), date date It is indexed on symbol,owner,date. THE INDICES TABLE The indices table links a stock symbol with one or several market indices: symbol varchar(12) not null, stockindex varchar(12) not null BUGS
Finance::BeanCounter and beancounter are so fresh that there are only missing features :) On a more serious note, this code (or its earlier predecessors) have been in use since the fall of 1998. Known bugs or limitations are documented in TODO file in the source package. SEE ALSO
beancounter.1, smtm.1, Finance::YahooQuote.3pm, LWP.3pm, Date::Manip.3pm COPYRIGHT
Finance::BeanCounter.pm (c) 2000 -- 2006 by Dirk Eddelbuettel <edd@debian.org> Updates to this program might appear at http://eddelbuettel.com/dirk/code/beancounter.html. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. There is NO warranty whatsoever. The information that you obtain with this program may be copyrighted by Yahoo! Inc., and is governed by their usage license. See http://www.yahoo.com/docs/info/gen_disclaimer.html for more information. ACKNOWLEDGEMENTS
The Finance::YahooQuote module by Dj Padzensky (on the web at http://www.padz.net/~djpadz/YahooQuote/) served as the backbone for data retrieval, and a guideline for the extension to the non-North American quotes which was already very useful for the real-time ticker http://eddelbuettel.com/dirk/code/smtm.html. perl v5.10.1 2010-06-13 BeanCounter(3pm)
All times are GMT -4. The time now is 10:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy