<< generate alphabets and append in the input values >>


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting << generate alphabets and append in the input values >>
# 1  
Old 10-24-2014
<< generate alphabets and append in the input values >>

Hi Team,
Pls help to get the desired output.

I have a input like below

Code:
nodecount=10
host=na7-db1-1-chi

nodecount can be 10 or 8 based on this we need a output (in single line) like below

Code:
na7-db1-1-chi:A na7-db1-2-chi:B na7-db1-3-chi:C na7-db1-4-chi:D na7-db1-5-chi:E na7-db1-6-chi:F na7-db1-7-chi:G na7-db1-8-chi:H na7-db1-9-chi:I na7-db1-10-chi:J

Regards
Kamal
# 2  
Old 10-24-2014
Try something like:
Code:
#!/bin/bash
nodecount=10
host=na7-db1-1-chi
IFS=- read -a H <<< "$host"
C=({A..Z})
for ((i=1; i<=nodecount; i++))
do
  printf "%s " "${H[0]}-${H[1]}-${i}-${H[3]}:${C[i-1]}"
done
echo


Last edited by Scrutinizer; 10-24-2014 at 05:20 AM.. Reason: Typo. Changed read -A to -a
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 10-24-2014
Thanks for you reply, It throwing some code error. Can you pls check

Code:
$  cat aa
#!/bin/bash
set -x
nodecount=10
host=na7-db1-1-chi
IFS=- read -A H <<< "$host"
C=({A..Z})
for ((i=1; i<=nodecount; i++))
do
  printf "%s " "${H[0]}-${H[1]}-${i}-${H[3]}:${C[i-1]}"
done
[oracle@etfvm20-db1-1-sfm:~]# aa
+ nodecount=10
+ host=na7-db1-1-chi
+ IFS=-
+ read -A H
./aa: line 5: read: -A: invalid option
read: usage: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]
+ C=({A..Z})
+ (( i=1 ))
+ (( i<=nodecount ))
+ printf '%s ' --1-:A
--1-:A + (( i++ ))
+ (( i<=nodecount ))
+ printf '%s ' --2-:B
--2-:B + (( i++ ))
+ (( i<=nodecount ))
+ printf '%s ' --3-:C
--3-:C + (( i++ ))
+ (( i<=nodecount ))
+ printf '%s ' --4-:D
--4-:D + (( i++ ))
+ (( i<=nodecount ))
+ printf '%s ' --5-:E
--5-:E + (( i++ ))
+ (( i<=nodecount ))
+ printf '%s ' --6-:F
--6-:F + (( i++ ))
+ (( i<=nodecount ))
+ printf '%s ' --7-:G
--7-:G + (( i++ ))
+ (( i<=nodecount ))
+ printf '%s ' --8-:H
--8-:H + (( i++ ))
+ (( i<=nodecount ))
+ printf '%s ' --9-:I
--9-:I + (( i++ ))
+ (( i<=nodecount ))
+ printf '%s ' --10-:J
--10-:J + (( i++ ))
+ (( i<=nodecount ))


Last edited by Scrutinizer; 10-24-2014 at 05:19 AM..
# 4  
Old 10-24-2014
Try read -a H, and then read the man bash
These 2 Users Gave Thanks to RudiC For This Post:
# 5  
Old 10-24-2014
thanks RudiC & Scrutinizer perfectly working !!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace alphabets in a string with their ASCII values

hi. I have a requirement where I need to REPLACE all alphabets from an alphanumeric input string into their respective ASCII decimal value. For example: If the input string is ABAC123, the output should be 65666567123 I am seeking a single line command, and I was trying searching for options... (21 Replies)
Discussion started by: kumarjt
21 Replies

2. UNIX for Dummies Questions & Answers

How to append values to a string?

Hi, Requesting some help with a problem I am facing with string function in UNIX. I wish to create 2 string variables: 1st header string containing output_1, output_2, .. , output_<n> and 2nd data string containing the filename separated by colon (":") and corresponding filesize separated by... (6 Replies)
Discussion started by: vkumbhakarna
6 Replies

3. Shell Programming and Scripting

How to generate a csv files by separating the values from the input file based on position?

Hi All, I need help for doing the following. I have a input file like: aaaaaaaaaabbbbbbbbbbbbbbbbbbbb cccbbbbbaaaaaadddddaaaabbbbbbb now I am trying to generate a output csv file where i will have for e.g. 0-3 chars of each line as the first column in the csv, 4-10 chars of the line as... (3 Replies)
Discussion started by: babom
3 Replies

4. Shell Programming and Scripting

Generate Codes based on start and End values of numbers in a column

Hello All, Could you please help with this. This is what I have: 506234.222 2 506234.222 2 506234.222 2 506234.222 2 508212.200 2 508212.200 2 333456.111 2 333456.111 2 333456.111 2 333456.111 2 But this is what I want: 506234.222 1 506234.222 2 506234.222 2 506234.222 3 (5 Replies)
Discussion started by: canimba
5 Replies

5. Shell Programming and Scripting

generate tabular output from an input text file in unix shell scripting

Hi, I have the output (as below) which i want it to be in a table. For e.g. space utilization in PSE on path /logs is 0% space utilization in PSE on path /logs/tuxedo/tuxlsp is 16% space utilization in PSE on path /ldvarlsp/lsp/log is 37% space utilization in PSE on path /home is 6%... (7 Replies)
Discussion started by: pkbond
7 Replies

6. Shell Programming and Scripting

Take user input and then append to another file

Hi, I have below line from the config file $__MR_CONFIG = 'userinput'; I want to get the value from the user for the "userinput" and then append the full line to another file. Can you please let me know how can I proceed on this? I am new to unix and your help is greatly appreciated.... (3 Replies)
Discussion started by: nav123
3 Replies

7. UNIX for Dummies Questions & Answers

To append \ in the input password

Hi I have the following issue i am going to ask from the user the password The password can have $ anywhere that is first last or in between but i have to append \ before the $ sign in the password can anyone please help For example o/p in the console will be like the... (3 Replies)
Discussion started by: ssuresh1999
3 Replies

8. Shell Programming and Scripting

Append values before a string

hi all, i have variables a and b with values, like a="/var/tmp/new.sh /var/tmp/new2.sh" b="/TEST" how i need to append the value "/TEST" before the values for the variable "a" so that i get the output as /TEST/var/tmp/new.sh /TEST/var/tmp/new2.sh plz help me Regards, NG (2 Replies)
Discussion started by: Nandagopal
2 Replies

9. UNIX for Dummies Questions & Answers

use awk to append values

Hi, I have a file like this: tag1:value1 tag2:value2 tag3:value3 tag1:value1 tag2:value2 tag3:value3 tag1:value1 tag2:value2 tag3:value3 and what i want is: value1 value2 value3 value1 value2 value3 (15 Replies)
Discussion started by: nickrick
15 Replies

10. Shell Programming and Scripting

Script to generate Average Values

11.60 12.35 12.49 12.99 13.09 12.91 13.48 14.16 14.18 13.23 13.17 13.15 13.71 13.35 13.12 13.00 12.79 12.83 12.54 12.89 12.89 12.47 12.94 13.00 13.41 13.09 13.09 12.09 12.76 12.93 13.67 13.14 13.01 12.39 12.78 12.86 12.61 12.50 12.11 12.98 12.90 12.77 12.56... (5 Replies)
Discussion started by: gagan.delouri
5 Replies
Login or Register to Ask a Question