grep required data from two columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep required data from two columns
# 1  
Old 02-15-2009
grep required data from two columns

hello,

I have output from a command and I need to filter some info out of that. I tried awk command but I can not grep what I am looking for:

Following is the output and I need to capture "disabled" for each volume from first column and report:

# vol status
Volume State Status Options
vol8 online raid_dp, flex snapmirrored=on,
snapmirrored fs_size_fixed=on,
read-only guarantee=volume(disabled)
vol9 online raid_dp, flex nosnap=on, snapmirrored=on,
snapmirrored create_ucode=on,
read-only convert_ucode=on,
fs_size_fixed=on,
guarantee=volume(disabled)
vol4 online raid_dp, flex snapmirrored=on,
snapmirrored fs_size_fixed=on,
read-only guarantee=volume(disabled)
vol5 online raid_dp, flex snapmirrored=on,
snapmirrored fs_size_fixed=on,
read-only guarantee=volume(disabled)
vol6 online raid_dp, flex snapmirrored=on,
snapmirrored fs_size_fixed=on,
read-only guarantee=volume(disabled)
vol7 online raid_dp, flex nosnap=on, snapmirrored=on,
snapmirrored create_ucode=on,
read-only convert_ucode=on,
fs_size_fixed=on,
guarantee=volume(disabled)
vol0 online raid_dp, flex root
vol1 online raid_dp, flex snapmirrored=on,
snapmirrored fs_size_fixed=on,
read-only guarantee=volume(disabled)
vol2 online raid_dp, flex snapmirrored=on,
snapmirrored fs_size_fixed=on,
read-only guarantee=volume(disabled)
vol10 online raid_dp, flex nosnap=on, snapmirrored=on,
snapmirrored create_ucode=on,
read-only convert_ucode=on,
fs_size_fixed=on,
guarantee=volume(disabled)
vol3 online raid_dp, flex snapmirrored=on,
snapmirrored fs_size_fixed=on, guarantee=none,
read-only

vol11 online raid_dp, flex snapmirrored=on,
snapmirrored fs_size_fixed=on,
read-only guarantee=volume(disabled)
logvol online raid_dp, flex nosnap=on, snapmirrored=on,
snapmirrored create_ucode=on,
read-only convert_ucode=on,
fs_size_fixed=on,
guarantee=volume(disabled)
vol12 online raid_dp, flex snapmirrored=on,
snapmirrored fs_size_fixed=on,
read-only guarantee=volume(disabled)


So I need to see the following as output:

vol8 guarantee=volume(disabled)
vol9 guarantee=volume(disabled)
vol4 guarantee=volume(disabled)

and so on ........

really appreciate your help.
# 2  
Old 02-15-2009
Hi,

Suppose you have the data in file:datavol

here is the code

Code:
#! /usr/bin/perl
use warnings;

open (DATAFILE, "+<datavol") or die $!;

my @mydatafile = <DATAFILE>;
my $data = join(" ",@mydatafile);

$data =~ s/(\n)//g;
#$data =~ s/, /,/g;
$data =~ s/(vol[0-9*])/\n$1/g;
my @arraydata = split(/\n/, $data);
foreach $value (@arraydata){
if ($value =~ /disabled/){
        print "\n";
        my @words = split(/\s+/,$value);
        print "$words[0] guarantee=volume(disabled)";
}
}
close DATAFILE;


Code:
[ahamed@localhost general]$ ./datavol.pl 

vol8 guarantee=volume(disabled)
vol9 guarantee=volume(disabled)
vol4 guarantee=volume(disabled)
vol5 guarantee=volume(disabled)
vol6 guarantee=volume(disabled)
vol7 guarantee=volume(disabled)
vol1 guarantee=volume(disabled)
vol2 guarantee=volume(disabled)
vol10 guarantee=volume(disabled)
vol11 guarantee=volume(disabled)
vol12 guarantee=volume(disabled)


Thanks
Ahamed Shameer
netgiz.net -
# 3  
Old 02-16-2009
Ahmed,
thanks for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print multiple required columns dynamically in a file using the header name?

Hi All, i am trying to print required multiple columns dynamically from a fie. But i am able to print only one column at a time. i am new to shell script, please help me on this issue. i am using below script awk -v COLT=$1 ' NR==1 { for (i=1; i<=NF; i++) { ... (2 Replies)
Discussion started by: balu1234
2 Replies

2. UNIX for Beginners Questions & Answers

UNIX shell script required to read two columns from xml

Hello All, I am new to unix scripting. I need to read FROMINSTANCE, FROMFIELD from below XML code and need to write a script for insert into SQ_EPIC values( "DID", "PROJECT_NAME") Select DID, PROJECT_NAME from EPIC<CONNECTOR TOINSTANCETYPE="Source Qualifier" TOINSTANCE="SQ_EPIC" TOFIELD="DID"... (7 Replies)
Discussion started by: sekhar.lsb
7 Replies

3. Shell Programming and Scripting

Help Need to fetch the required data

Hi Guys, Am in need of your help one more time on my real data. I have a file which contains more than thousand lines of data Live data shown for 4 iterations. We have more than thousand lines of data:- -------------------------------------------------------------------------- ... (4 Replies)
Discussion started by: rocky2013
4 Replies

4. Shell Programming and Scripting

Required help to print diff columns for 2 patterns using awk

Hi All, I need help for below scenario : I have a principals.xml_24092012backup file : cat principals.xml_24092012backup </user> <user username="eramire" password="2D393C01720749256303D204826A374D9AE9ABABBF8A"> <roleMapping rolename="VIEW_EVERYTHING"/> </user> ... (2 Replies)
Discussion started by: kiran_j
2 Replies

5. Shell Programming and Scripting

Checking the required columns in File

Hello Experts, File contains 10 columns with | delimeter. 1,3,4,5,7,9 columns are required columns means it should contains values. i need those records, rest of it will contain or not contain data. test1.txt: a@a.com|a|b|c|d|e|f|g|h|i |a|b|c|d|e|f|g|h|i b@b.com|a||c|d|e|f|g|h|i... (7 Replies)
Discussion started by: muralikri
7 Replies

6. Shell Programming and Scripting

Checking required columns in the file

Hi, File contains with TAB delimeter file,i want check the 2,3 are not null test1@gmail.com 100 test test2@gmail.com 101 test test3@gmail.com test test4@gmail.com 102 OUTPUT test1@gmail.com 100 test test2@gmail.com 101 test Please help me with one single command in... (2 Replies)
Discussion started by: muralikri
2 Replies

7. UNIX for Dummies Questions & Answers

Suggestion to convert data in rows to data in columns

Hello everyone! I have a huge dataset looking like this: nameX nameX 0 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 ............... nameY nameY 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 ..... nameB nameB 0 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 ..... (can be several thousands of codes) and I need... (8 Replies)
Discussion started by: kush
8 Replies

8. UNIX for Advanced & Expert Users

sort out the required data

Hi All, I have a file 1.txt which has the duplicate dns entries as shown: Name: 000f9fbc6738.net.in|Addresses: 10.241.66.169, 10.84.2.222,212.241.66.170 Name: 001371e8ed3e.net.in|Addresses: 10.241.65.153, 10.84.1.101 Name: 00e06f5bd42a.net.in|Addresses: 10.72.19.218,... (6 Replies)
Discussion started by: imas
6 Replies

9. Shell Programming and Scripting

shell script required to convert rows to columns

Hi Friends, I have a log file as below siteid = HYD spc = 100 rset = RS_D_M siteid = DEL spc = 200 rset = RS_K_L siteid = DEL2 spc = 210 rset = RS_D_M Now I need a output like column wise as below. siteid SPC rset HYD 100 RS_D_M (2 Replies)
Discussion started by: suresh3566
2 Replies

10. Shell Programming and Scripting

Help required in grep command

Hi all, I need some help in grep command in a ksh script. Actually, i need to list all files having the file name like "BORD*.DAT" but exclude the files (from the list) having name like "BORD*mgt*.DAT". For that i used the following command: ls | grep "BORD*.DAT" | grep -v "BORD*mgt*.DAT" ... (4 Replies)
Discussion started by: panzer
4 Replies
Login or Register to Ask a Question