convert list in a command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting convert list in a command
# 1  
Old 12-14-2011
convert list in a command

Hello,
i would make a script that generate SWITCH commands to create zone in a SAN, i have this file:
Code:
 ## zone:z_CGBVMH1_FC0_to_EVA1_CTRL_A_1
p_CGBVMH1_FC0; p_EVA1_CTRL_A_1
 ## zone:z_CGBVMH1_FC0_to_EVA1_CTRL_B_1
p_CGBVMH1_FC0; p_EVA1_CTRL_B_1
 ## zone:z_CGBVMH1_FC2_to_EVA1_CTRL_A_1
p_CGBVMH1_FC2; p_EVA1_CTRL_A_1
 ## zone:z_CGBVMH1_FC2_to_EVA1_CTRL_B_1
p_CGBVMH1_FC2; p_EVA1_CTRL_B_1
 ## zone:z_CGBVMH2_FC0_to_EVA1_CTRL_A_1
p_CGBVMH2_FC0; p_EVA1_CTRL_A_1
 ## zone:z_CGBVMH2_FC0_to_EVA1_CTRL_B_1
p_CGBVMH2_FC0; p_EVA1_CTRL_B_1

i would create a file with:
Code:
zoneAdd "zonename","alias1,alias2"

zoneAdd "z_CGBVMH2_FC0_to_EVA1_CTRL_B_1","p_CGBVMH2_FC0;p_EVA1_CTRL_B_1"

Moderator's Comments:
Mod Comment Please use code tags!

Last edited by zaxxon; 12-14-2011 at 07:52 AM.. Reason: code tags, see PM
# 2  
Old 12-14-2011
Based on the input given ..
Code:
$ nawk -F: '/^#/{print "zoneAdd \""$2"\""}!/^#/{print "\""$0"\""}' infile | paste -d',' - -
zoneAdd "z_CGBVMH1_FC0_to_EVA1_CTRL_A_1","p_CGBVMH1_FC0; p_EVA1_CTRL_A_1"
zoneAdd "z_CGBVMH1_FC0_to_EVA1_CTRL_B_1","p_CGBVMH1_FC0; p_EVA1_CTRL_B_1"
zoneAdd "z_CGBVMH1_FC2_to_EVA1_CTRL_A_1","p_CGBVMH1_FC2; p_EVA1_CTRL_A_1"
zoneAdd "z_CGBVMH1_FC2_to_EVA1_CTRL_B_1","p_CGBVMH1_FC2; p_EVA1_CTRL_B_1"
zoneAdd "z_CGBVMH2_FC0_to_EVA1_CTRL_A_1","p_CGBVMH2_FC0; p_EVA1_CTRL_A_1"
zoneAdd "z_CGBVMH2_FC0_to_EVA1_CTRL_B_1","p_CGBVMH2_FC0; p_EVA1_CTRL_B_1"

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 12-14-2011
or this
Code:
$ awk -F: '/^ #/ {a=$2;next}{print "zoneAdd \"" $0 "\",\"" a "\""}' infile
zoneAdd "p_CGBVMH1_FC0; p_EVA1_CTRL_A_1","z_CGBVMH1_FC0_to_EVA1_CTRL_A_1"
zoneAdd "p_CGBVMH1_FC0; p_EVA1_CTRL_B_1","z_CGBVMH1_FC0_to_EVA1_CTRL_B_1"
zoneAdd "p_CGBVMH1_FC2; p_EVA1_CTRL_A_1","z_CGBVMH1_FC2_to_EVA1_CTRL_A_1"
zoneAdd "p_CGBVMH1_FC2; p_EVA1_CTRL_B_1","z_CGBVMH1_FC2_to_EVA1_CTRL_B_1"
zoneAdd "p_CGBVMH2_FC0; p_EVA1_CTRL_A_1","z_CGBVMH2_FC0_to_EVA1_CTRL_A_1"
zoneAdd "p_CGBVMH2_FC0; p_EVA1_CTRL_B_1","z_CGBVMH2_FC0_to_EVA1_CTRL_B_1"

This User Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert list of numbers to text range

Hi, I'd like to take a list of numbers (with a prefix) and convert to a range, for example: cn001 cn004 cn016 cn017 cn018 cn019 cn020 cn021 cn031 cn032 cn038 cn042 cn043 cn044 cn045 (5 Replies)
Discussion started by: chrissycc
5 Replies

2. Shell Programming and Scripting

Shell script to convert IP range csv into a list of single IP's

Hi All, I am looking for some help to convert a csv with IP ranges in.. in the format e.g. 1.1.1.2, 1.1.1.5 2.1.1.10, 2.1.1.20 and would be looking to output as follows: 1.1.1.2 1.1.1.3 1.1.1.4 1.1.1.5 2.1.1.10 2.1.1.11 etc etc up to 2.1.1.20 I have tried a few google... (4 Replies)
Discussion started by: zippyzip
4 Replies

3. Shell Programming and Scripting

Convert for command from DOS to SHELL

Well, this command has served me quite well under DOS for %%X in (*.txt) do COMMAND however in linux it just outputs: "./install.sh line 1: '%%x': not a valid identifier. Ideas ? Thanks in advance (2 Replies)
Discussion started by: pasc
2 Replies

4. Shell Programming and Scripting

Convert a two-column list into a csv

Hi experts, I have a very large (1.5M lines), sorted but unstructured list that looks like this: process_nameA valueA process_nameA valueA ... process_nameB valueB process_nameB valueB ... process_nameN valueN I'd like to turn this into a csv. The values are all... (4 Replies)
Discussion started by: abercrom
4 Replies

5. UNIX for Dummies Questions & Answers

How convert space separated list to matched columns?

Hi I have been racking my (limited) brains to get this to work without success I have a file output which is a list of lists - ie a single column of data that is separated by space into sub lists below - I need to both split this so that each list is in a separate column (eg tab or semicolon... (8 Replies)
Discussion started by: Manchesterpaul
8 Replies

6. Shell Programming and Scripting

Convert a list of word/terms into their Regexp representation

Ok this might sound pretty weird but here is the request. Running on a linux system in bash or Perl (i really don't know perl but the end user has a few pearl script already) Start File looks something like this (4000 entries) TEST PLAN T//TF T-TF TEST (T) Hacker ... I am thinking about... (3 Replies)
Discussion started by: oly_r
3 Replies

7. Shell Programming and Scripting

Script to convert row to list

Hello, I have data which is basically a set of rows in which names having the same homophonic values are stored. I want to convert the data into lines such that the first word of the database is treated as the anchor and each subsequent word is appended to it with a column. An example... (5 Replies)
Discussion started by: gimley
5 Replies

8. Programming

c++ function to convert a linear list to circular list

hi all, i need a c++ function which converts a linear list to circular. presently i am working with two files. i.e., one linear list file. and one circular list file to do some operations. i thought it will be helpful if there is a function that converts a linear list to circular n undo the... (1 Reply)
Discussion started by: vidyaj
1 Replies

9. Shell Programming and Scripting

Convert perl qw list to text file list?

Does anyone have a good example? I am having trouble looping.. Thanks (1 Reply)
Discussion started by: mrlayance
1 Replies

10. Shell Programming and Scripting

Convert Sed command to perl command

Hello, Can any perl experts help me convert my sed string to perl. I am unsuccessful with this. I have to remove this string from html files OAS_AD('Top'); I have come up with this. However the requirement is in perl. for find in $(find . -type f -name "file1.html") ; do cat $find |... (2 Replies)
Discussion started by: abacus
2 Replies
Login or Register to Ask a Question