Sponsored Content
Full Discussion: Perl array with row header
Top Forums Shell Programming and Scripting Perl array with row header Post 302488861 by Ikon on Tuesday 18th of January 2011 04:16:54 PM
Old 01-18-2011
Perl array with row header

Here is the csv file file i have:

Code:
ServerName, IPAddress, Gateway, Notes
ServerA, 192.168.1.100, 192.168.1.1, This is some server
ServerB, 192.168.1.110, 192.168.1.1, This is some other server
ServerC, 192.168.1.120, 192.168.1.1, This is some other other server

I would like to have the following:

$Servername[0] = ServerA
$IPAddress[0] = 192.168.1.100
...
$Servername[1] = ServerB
...
etc...

The column headers could be any number of columns or names.

Im actually taking the output of wmic on a linux server after querying the windows via WMI.

Smilie

Here is a sample:
Code:
$Selection="*";
$WMIClass="Win32_OperatingSystem";
@Output=`wmic --delimiter "," --user "$Username"%"$Password" //$TargetHost \"Select $Selection from $WMIClass\"`;

Which would output something like:
Code:
#wmic --user DOMAIN/USERNAME%PASSWORD //Someserver "Select * FROM Win32_LocalTime"

CLASS: Win32_LocalTime
Day|DayOfWeek|Hour|Milliseconds|Minute|Month|Quarter|Second|WeekInMonth|Year
18|2|13|0|20|1|1|56|4|2011

---------- Post updated at 04:16 PM ---------- Previous update was at 03:19 PM ----------

I got it figured out:
Code:
$rowcount=0;
foreach (@Output) {
    @line = split(',',$_);
    $colcount=0;
    foreach $col (@Columns) {
        $$col[$rowcount] = $line[$colcount];
        $colcount++;
    }
    $rowcount++;
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

insert header row into .xls

Hello, I am building an .xls file extracting info from a DB to be eventually emailed. All is good except how do I put in a header row.. like date, name of report etc. before the columns with the actual column name and data? Thanks for any assistance.. the below is after I have signed into... (11 Replies)
Discussion started by: Tish
11 Replies

2. UNIX for Dummies Questions & Answers

split header row into one column

So, I have a massive file with thousands of columns I want a list of the headers in one column in another file. So I need to strip off the top line (can use head-1) But how can I convert from this format: A B C D E F G to A B C D E F G (6 Replies)
Discussion started by: polly_falconer
6 Replies

3. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies

4. Shell Programming and Scripting

Exclude the header row in the file to validate

Hi All, File contains header row.. we need to exclude the header row...no need to validate the first row in the file. Data in the file should take valid data(two columns)..we need to exclude the more than two columns in the file except the first line. email|firstname a|123|100 b|345... (4 Replies)
Discussion started by: bmk
4 Replies

5. Shell Programming and Scripting

Add column header and row header

Hi, I have an input like this 1 2 3 4 2 3 4 5 4 5 6 7 I would like to count the no. of columns and print a header with a prefix "Col". I would also like to count the no. of rows and print as first column with each line number with a prefix "Row" So, my output would be ... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

6. UNIX for Dummies Questions & Answers

File Row Line Count without Header Footer

Hi There! I am saving the file count of all files in a directory to an output file using: wc -l * > FileCount.txt I get: 114 G4SXORD 3 G4SXORH 0 G4SXORP 117 total But this count includes header and footer. I want to subtract 2 from the count and get ... (7 Replies)
Discussion started by: gagan8877
7 Replies

7. Shell Programming and Scripting

Exclude the header row while splitting the file

Hi All, i have script like ... "TYPE_ID" "ID" "LIST_ID" "18" "52010" "1059" "18" "52010" "1059" "18" "52010" "1059" "18" "52010" "1059" i am using the below code it's not taking the header row. awk -F"\t" -v file=test1.txt -v file1=test2.txt ' { if(... (7 Replies)
Discussion started by: bmk
7 Replies

8. Shell Programming and Scripting

How to display the header of a matched row in a file?

Hi, So I am trying to print the first row(header) first column alongwith the matched value. But I am not sure how do I print the same, by matching a pattern located in the file eg File contents Name Place Jim NY Jill NJ Cathy CA Sam TX Daniel FL And what I want is... (2 Replies)
Discussion started by: sidnow
2 Replies

9. Shell Programming and Scripting

At text to field 1 of header row using awk

I am just trying to insert the word "Index" using awk. The below is close but seems to add the word at the end and I can not get the syntax correct to add from the beginning. Thank you :). awk -F'\t' -v OFS='\t' '{ $-1=$-1 OFS "Index"}$1=$1' file current output Chr Start End ... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. Shell Programming and Scripting

awk to skip header row and add string to field

The awk below does put in VUS in the 9th field but I can not seem to skip the header then add the VUS. I tried to incorporate NR >=2 and NR > 1 with no luck. Thank you :). input Chr Start End Ref Alt Func.refGene PopFreqMax CLINSIG Classification chr1 43395635 ... (5 Replies)
Discussion started by: cmccabe
5 Replies
NOS-TUN(8)						    BSD System Manager's Manual 						NOS-TUN(8)

NAME
nos-tun -- implement ``nos'' or ``ka9q'' style IP over IP tunnel SYNOPSIS
nos-tun -t tunnel -s source -d destination -p protocol_number [source] target DESCRIPTION
The nos-tun utility is used to establish an nos style tunnel, (also known as ka9q or IP-IP tunnel) using a tun(4) kernel interface. Tunnel is the name of the tunnel device /dev/tun0 for example. Source and destination are the addresses used on the tunnel device. If you configure the tunnel against a cisco router, use a netmask of ``255.255.255.252'' on the cisco. This is because the tunnel is a point-to-point interface in the FreeBSD end, a concept cisco does not really implement. Protocol number sets tunnel mode. Original KA9Q NOS uses 94 but many people use 4 on the worldwide backbone of ampr.org. Target is the address of the remote tunnel device, this must match the source address set on the remote end. EXAMPLES
This end, a FreeBSD box on address 192.168.59.34: nos-tun -t /dev/tun0 -s 192.168.61.1 -d 192.168.61.2 192.168.56.45 Remote cisco on address 192.168.56.45: interface tunnel 0 ip address 192.168.61.2 255.255.255.252 tunnel mode nos tunnel destination 192.168.59.34 tunnel source 192.168.56.45 AUTHORS
Nickolay N. Dudorov <nnd@itfs.nsk.su> wrote the program, Poul-Henning Kamp <phk@FreeBSD.org> wrote the man-page. Isao SEKI <iseki@gongon.com> added a new flag, IP protocol number. BUGS
We do not allow for setting our source address for multihomed machines. BSD
April 11, 1998 BSD
All times are GMT -4. The time now is 03:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy