string with blank spaces


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers string with blank spaces
# 1  
Old 04-16-2008
Tools string with blank spaces

I have a file that has dates like this:
date FINAL_RESULT; 7
date FINAL_RESULT; 2
date FINAL_RESULT; 5

With this command: seira=`cut -f2 -d\; tes.txt` i take the date FINAL RESULTs and i store them on variable seira.then seira look like this: 6 3 8
I want to read seira and make a sum of all results 7+2+5 etc. i don't know how many records there are in the file. So i want to read seira with the next loop using while but it doesn 't work. i don't want to use grep or awk. I want to use while and cut but it is wrong. Can someone help me please

while [ "$seira" != "" -a "$seira" != " " ]
do
sum=0
pros1=`cut -f1 -d \ $seira`
pros2=`cut -f2 -d \" " $seira`
sum=`expr $sum+$pros1`
seira=$pros2
done

Can someone correct it? I have a big problem and i am in a big need.PLZ!
# 2  
Old 04-16-2008
Code:
sum=0
for s in $seira; do
  sum=`expr $sum + $s`
done

You might as well feed the loop straight from the original cut, though:

Code:
cut -d; -f2 tes.txt |
while read num; do
  sum=`expr $sum + $num`
done

Any particular reason you're not using awk?

Code:
awk '{ sum += $NF} END { print sum }' tes.txt

# 3  
Old 04-16-2008
thanks

thank you men but the first code

sum=0
for s in $seira; do
sum=`expr $sum + $s`
done

this is in the while loop or it is appart. When will it end?
# 4  
Old 04-16-2008
This is instead of a while loop. It loops over the whitespace-separated elements in $seira
# 5  
Old 04-16-2008
Tools Thank you men

IT WORKED! THANKS .finally i managed to do it. God bless you
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add Blank Spaces in text, to perform beter alignment of the string

Hi Guru, I need some advice on how to add blank spaces to the code, rather than me just adding <space-bar spaces> which does not work. Current output of the code File System Backed Up - ALL_LOCAL_DRIVES Daily - Incremental Backup Schedule - 1 Month Retention • 7pm - PRD... (2 Replies)
Discussion started by: Junes
2 Replies

2. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

3. UNIX for Dummies Questions & Answers

Remove blank spaces

Dear Masters, I want to remove all lines with blank spaces input file: a|abc|0|1 a|abc|2|3 b||3|5 c|def||7 d|def|0|1 Expected: a|abc|0|1 a|abc|2|3 d|def|0|1 I did this awk -F'|' '!/^$/' input (4 Replies)
Discussion started by: radius
4 Replies

4. Shell Programming and Scripting

Remove blank spaces

Gents, Please can you help me.. to remove blank spaces :) Input ABSOLUTE , ,FALSE ,1035 ,28 ,669 ,1817.0 ,CORREL BEFORE ,1 ABSOLUTE , ,FALSE ,1035 ,28 ,686 ,1817.0 ,CORREL BEFORE ,1 ABSOLUTE , ,FALSE ,1035 ,28 ,670 ,1819.0 ,CORREL BEFORE ,1 ABSOLUTE , ,FALSE ... (4 Replies)
Discussion started by: jiam912
4 Replies

5. Shell Programming and Scripting

append blank spaces at the end of a variable string

Hello, could you please help with this one. I have an input file like this: 123,4567,89000 123456789,9876543,12 and for the output I need strings to be with the fixed length, let's say 15, and if the string is -lt 15 to be populated with blanks at the end until it reach 15, like this: 123 ,4567... (1 Reply)
Discussion started by: apenkov
1 Replies

6. UNIX for Dummies Questions & Answers

selective removal of blank spaces in string

Hi, I'm a newbie to shell scripting and I have the following problem: I need all spaces between two letters or a letter and a number exchanged for an underscore, but all spaces between a letter and other characters need to remain. Searching forums didn't help... One example for clarity: ... (3 Replies)
Discussion started by: Cpt_Cell
3 Replies

7. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

8. Shell Programming and Scripting

blank spaces getting deleted

I have to filter out data from a file based on the value of first three characters of each record I have used the following logic FIN=$LOC/TEST2.TXT FEEDFILE=$LOC/TEST1.TXT while read FDROW do FEEDROW=$FDROW; DTYPE=`echo $FEEDROW |cut -c 1-3` if ; then echo $FEEDROW >> $FIN... (5 Replies)
Discussion started by: gander_ss
5 Replies

9. Shell Programming and Scripting

remove blank spaces in a string

can any help how to remove blank spaces in a string? STR="GOOD BYE" by removing blank spaces, the string should be GOOD,BYE thanks in advance (2 Replies)
Discussion started by: spandu
2 Replies

10. Shell Programming and Scripting

howtodelete blank spaces

sry im new to this...another qns.. if i have a line in the normal shell the file is email.scp. it contains a txt file eg hello.txt that contain this infomation. k@hotmail.com j@jotm.com how do i delete away the blank spaces after the k@hotmail.com..i dun wan any blank spaces after the... (2 Replies)
Discussion started by: forevercalz
2 Replies
Login or Register to Ask a Question