Help me to format this data please


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help me to format this data please
# 8  
Old 04-16-2009
Quote:
Originally Posted by Ikon
This is the 3rd post by you relating to this same script. You have ONLY asked others to do the script for you. If you have no code you can share that you have tried, this must be school work. As you are obviously not a system administrator or programmer.

This forum is here to help people, not do their work. Im sure if you do some searching of the forum you will find some similar topics that can lead you in the correct direction.
I tend to agree with Ikon's comments above. Some people might view them as a bit tough, but he has a good point.

glev2005,

Experts here are not your private employees to do you work for you. They help because they are generous with their time and knowledge. You have a responsibility to actually do your share of the work and not simply ask people here to do all your work for you.
# 9  
Old 04-17-2009
Ok, well just to clarify.. I am not a student, this is not a school project.. I am trying to do some work on a Macintosh Network, and I use BASH, which I am far from an expert in, to do so for the most part. I hear all of your comments, but it is much better to hear them from a moderator, and not some opinionated user who really should just move on if he doesnt like my question. I know quite a lot about some subjects, and am happy to impart knowledge to people of all skill levels, and if i'm not, then I dont and I keep quiet.


That being said, I have narrowed down to getting each number on a separate line, I now have to take the numbers on each line and add them up, I suppose using expr.. Can I please have some help with this?

also, how do i create code tags? <code> ? </code>
# 10  
Old 04-17-2009
Code:
[code]
my code, data file whatnot goes here
more of the whatnot
[/code]

here're a number of ways to add numbers from a file (one number per line):
Code:
echo `sed -e 's/$/+/' file.txt` 0 | bc
OR
awk '{sum+=$1} END {print sum}' file.txt
OR
echo `tr '\n' '+' < file.txt` 0 |bc
OR
paste -sd+ file.txt |bc
OR
printf "%d\n" $(( `tr -s '\n' '+' < file.txt` 0 ))

# 11  
Old 04-17-2009
IF all the lines were in one file you could do the following to could the second colum.

Code:
# cat server.lst
server_a 2
server_b 4
server_c 1

#  awk '{s += $2} END {print s}' server.lst
7

# 12  
Old 04-17-2009
If there are separate files with just a number in them:

Code:
# cat servera.server
1

# cat serverb.server
9

# cat test.sh
declare -a FILES
FILES=`ls *.server`
COUNT=0
for PRT in ${FILES[@]}
do
        UPD=`cat $PRT`
        COUNT=$(( $COUNT+$UPD ))
done
echo "Total: $COUNT"

# sh test.sh
Total: 10

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format DATA

Input File AU01NAS002,FCNVX133800117,AU01_Melbourne_Australia,ATT,Internal,NAS SILVER,12287.99,3293.98,6946.02 AU01NAS002,FCNVX133800117,AU01_Melbourne_Australia,ATT,Internal,NAS ARCHIVE,12287.99,3327.12,6912.87... (6 Replies)
Discussion started by: greycells
6 Replies

2. UNIX for Dummies Questions & Answers

Data format

Dear Masters, I have problem with my data result I do vim data result AAA111|^/CANADA|80 BAA111|^/PARIS|60 string with blue colour appears..how can I remove it? So when I do vi, blue string should not appear tks (2 Replies)
Discussion started by: radius
2 Replies

3. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

4. Programming

Transforming data to other format

Dear All I would like to transform data from one format to another format. my Input: 0 0 1 0 1 0.308 0 2 0.554 0 3 0.287 output: Z (0,0)= 1 Z (0,1)=0.308 Z (0,2)=0.554 Z (0,3)=0.287 (2 Replies)
Discussion started by: bala06
2 Replies

5. Shell Programming and Scripting

How to get data in a specified format

Hii , I have a huge set of data stored in file a.dat as shown below a.dat: 081276A BURMA Date: 1976/ 8/12 Centroid Time: 23:26:51.8 GMT Lat= 26.55 Lon= 97.12 Depth= 15.0 Half duration= 2.2 Centroid time minus hypocenter time: 5.6 Moment Tensor: Expo=24 7.840 -2.440... (4 Replies)
Discussion started by: reva
4 Replies

6. Shell Programming and Scripting

getting the data in some format

HI i am writing a shell script to generate some files having data in some format. for this i am using awk -F":" '{printf("%-20s:%-20s:%-20s:%-20s:%-15s:%-3s:%-19s:%-2s:%-20s:%-15s:%-2s\n", $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)}' $DIALPBIN/temp1.txt > ${DIALPBIN}/temp2.txt this helps in... (1 Reply)
Discussion started by: priyanka3006
1 Replies

7. UNIX for Dummies Questions & Answers

Please help me format this data

STMC429 (192.168.171.72) 2008-11-24 14:18:09.412 softwareupdate Loading CatalogURL http://creativesus.conair.lan:8088/index.sucatalog No new software available. There are no updates to install STMC444 (3) (192.168.171.116) 2008-11-24 14:14:31.771 softwareupdate Loading CatalogURL... (4 Replies)
Discussion started by: glev2005
4 Replies

8. Shell Programming and Scripting

format the extracted data

I have executed the following code. #! /bin/ksh ############################ # AFI Monitor Script ############################ . /db2/uszlad48/sqllib/db2profile export mondir=/home/bmwdev1/script/krishna/arc export monlog=$mondir/rcbl2_`date +%Y%m%d`.log # connect to DB db2 connect... (2 Replies)
Discussion started by: kmanivan82
2 Replies

9. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies

10. Shell Programming and Scripting

format data

i have this data: GREEN LIST : 12321 34534 GREEN LIST : 45645 --- 23423 WHITE LIST : 23479 34534 75483 76924 12345 --- 12351 56778 --- 23330 GREEN LIST : 23567 the output must be: GREEN LIST : 12321 GREEN LIST : 34534 GREEN LIST : 45645 --- 23423 (2 Replies)
Discussion started by: inquirer
2 Replies
Login or Register to Ask a Question