Need script to format data specifically


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need script to format data specifically
# 1  
Old 12-10-2010
Need script to format data specifically

Hi all,
I need a script specially using loops to print below output...
variables x, a and b will be read from user...
x a b
x+1 a b+1
x+2 a b+2
x+3 a+1 b
x+4 a+1 b+1
x+5 a+1 b+2

for example....
1 21 31
2 21 32
3 21 33
4 22 31
5 22 32
6 22 33

---------- Post updated at 07:31 PM ---------- Previous update was at 07:29 PM ----------

this is the output example...
1 21 31
2 21 32
3 21 33
4 22 31
5 22 32
6 22 33
# 2  
Old 12-10-2010
Code:
#!/bin/ksh

x=$1 ; a=$2 ; b=$3

echo $x $a $b
echo `expr $x + 1` $a `expr $b + 1`
echo `expr $x + 2` $a `expr $b + 2`
echo `expr $x + 3` `expr $a + 1` $b
.....
.....

R0H0N
# 3  
Old 12-10-2010
Here is a loops-based solution
Code:
#!/bin/ksh93

read x?"Enter values for X A B: " a b

for ((i=0;i<2;i++))
do
   for ((j=0;j<3;j++))
   do
      printf "%d %d %d\n" $(((i*3)+j+x)) $((a+i)) $((b+j))
   done
done

Code:
$ ./example
Enter values for X A B: 1 21 31
1 21 31
2 21 32
3 21 33
4 22 31
5 22 32
6 22 33

# 4  
Old 12-10-2010
I want to do this using loop
Code:
recreatevg -y datavg1 -L /SH3 -Y NA $medatadisk1 $medatadisk2
recreatevg -y datavg2 -L /SH3 -Y NA $medatadisk3 $medatadisk4
recreatevg -y datavg3 -L /SH3 -Y NA $medatadisk5 $medatadisk6
recreatevg -y datavg4 -L /SH4 -Y NA $medatadisk7 $medatadisk8
recreatevg -y datavg5 -L /SH4 -Y NA $medatadisk9 $medatadisk10
recreatevg -y datavg6 -L /SH4 -Y NA $medatadisk11 $medatadisk12

---------- Post updated at 08:30 PM ---------- Previous update was at 08:18 PM ----------

It gives me this error

Code:
ibmsupt@MTSsupport61/tmp>cat seth1.sh
#!/bin/ksh93

read x?"Enter values for X A B: " a b

for ((i=0;i<2;i++))
do
   for ((j=0;j<3;j++))
   do
      printf "%d %d %d\n" $(((i*3)+j+x)) $((a+i)) $((b+j))
   done
done
ibmsupt@MTSsupport61/tmp>sh seth1.sh
Enter values for X A B: 1 21 31
seth1.sh[5]: 0403-057 Syntax error at line 5 : `(' is not expected.
ibmsupt@MTSsupport61/tmp>sh -x seth1.sh
+ read x?Enter values for X A B:  a b
Enter values for X A B: 1 21 31
seth1.sh[5]: 0403-057 Syntax error at line 5 : `(' is not expected.


Last edited by Franklin52; 12-10-2010 at 11:02 AM.. Reason: Please use code tags, thank you
# 5  
Old 12-11-2010
It would appear that you are using bash to invoke a ksh93 shell script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Perl -- Script to re-format data

Hi, I have a file with data in the following format BOX -1.000000 -1.000000 0.000000 30.00000 14.00000 0.1000000 0.000000 0.000000 0.000000 0.000000 0.000000 CYLINDER 3.595000 2.995000 0.000000 0.5100000 2.000000 Z 0.000000 0.000000 0.000000 I want to convert these files... (1 Reply)
Discussion started by: lost.identity
1 Replies

3. Shell Programming and Scripting

Converting text files to xls through awk script for specific data format

Dear Friends, I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls. The input is as follows: >gi|1234|ref| Query = 1 - 65, Target = 1677 - 1733 Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46 fd sdfsdfsdfsdf fsdfdsfdfdfdfdfdf... (6 Replies)
Discussion started by: Amit1
6 Replies

4. UNIX for Dummies Questions & Answers

How to retrive data from DB(Aqua studio) in CVS format using UNIX script?

I am using aqua studio DB. I need to retrive the data from my database using uxin script in .csv format. i am using select query along with the joins. my o/p in the DB is of the below format. Cycle IDCycle StatusRecord 98N-0000ACV23-3636FCliet Level (Af)Success1689393HF-J7879-09090RCliet Level... (1 Reply)
Discussion started by: Mugivz
1 Replies

5. Shell Programming and Scripting

awk - script help: column to row format of data allignment?

Experts Good day, I have the following data, file1 BRAAGRP1 A2X B2X C2X D2X BRBGRP12 A3X B3X Z10 D09 BRC1GRP2 LO01 (4 Replies)
Discussion started by: rveri
4 Replies

6. Shell Programming and Scripting

Help with perl script to output data in table format...

Hello, I need help with a perl script that will process a text file and match virtual server name to profile(s). the rest will be ignored. Virtual server name follows the word "virtual" in the begging of the line. There could be multiple profiles assigned to one virtual server. For example, ... (3 Replies)
Discussion started by: besogon
3 Replies

7. Shell Programming and Scripting

Perl Script for reading table format data from file.

Hi, i need a perl script which reads the file, content is given below. and output in new file. TARGET DRIVE IO1 IO2 IO3 IO4 IO5 ------------ --------- --------- --------- --------- --------- 0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies

8. UNIX for Advanced & Expert Users

shell script to format .CSV data

Hi all, I have written a shell script to search a specified directory (e.g. /home/user) for a list of specific words (shown as ${TMPDIR}/wordlist below). The script works well enough, but I was wondering if there was a way to display the line number that the word is found on? Thanks! cat... (1 Reply)
Discussion started by: tmcmurtr
1 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

Shell script to format a .CSV data

Hi There I needed to write a Unix shell script which will pick up the data from a .CSV file and reformat it as per the requirement and write it to another .CSV file. Currently I am in the proess of Data Import to "Remedy System" (A one kind of incident mangement Application) and this... (8 Replies)
Discussion started by: Uday1982
8 Replies
Login or Register to Ask a Question