Computing.Net > Forums > Unix > problem with shell script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

problem with shell script

Reply to Message Icon

Name: Sora
Date: May 22, 2004 at 23:12:43 Pacific
OS: Win98
CPU/Ram: P2 350
Comment:

relatively new to this. Hope someone can help me.

I need to read from a file.
11 columns, each column is separated by a space. contains numercial values only. each rows can have integer of value 1-5 & a "-" .

So what I did was to use
a while loop

basically something like this

while read a b c d e f g h i j k
do
x=`expr $b $c... $k`
dont <input file


#a can be ignore at the moment. for it is something like identification

but however becoz of the "-" in the rows, i need to replace each "-" with a 0. but not sure how to do so.
i know it is something like ${var:0}
but i am not sure how to implement into the script... plus after so I need to count the number of rows which doesnt contain "-"..

Really hope someone can help me out here.



Sponsored Link
Ads by Google

Response Number 1
Name: WilliamRobertson
Date: May 23, 2004 at 10:48:57 Pacific
Reply:

How about

#!/bin/ksh

integer a b c d e f g h i j k

sed 's/-/0/g' xx.dat | while read a b c d e f g h i j k
do
print $a $b $c $d $e $f $g $h $i $j $k
done


0

Response Number 2
Name: Sora
Date: May 24, 2004 at 03:02:45 Pacific
Reply:

Thank you. it works. now just need to know how to count the "-".. thanks so much


0

Response Number 3
Name: Sora
Date: May 24, 2004 at 04:01:32 Pacific
Reply:

if let's say i have this

1234567 1 2 3 4 5 5 6 7 8 -
and many other simlar lines..

i need to count the number of int from the second columns onwards. How do i tell the system to like check for every "-", and do a subtraction from 10. coz 10 is the total number of columns beside the one column.
anyone has a gd idea????


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: problem with shell script

help with shell script www.computing.net/answers/unix/help-with-shell-script/7840.html

help with shell scripts www.computing.net/answers/unix/help-with-shell-scripts/8013.html

Help with shell scripts www.computing.net/answers/unix/help-with-shell-scripts/4729.html