Columns count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Columns count
# 1  
Old 03-01-2010
Columns count

I'm writting a script that will get the logical volumes from a volume group and check for mirroring. I'm using a while read line command. I need to be able to count the columns for the output and if it is <= 3 save the logical volume to a file and if it is > 3 continue. How do I capture the number of collumns in the line? Here is what I have;

Code:
lsvg -o|lsvg -i -l|awk '{print $1}' >/tmp/lvols.txt

Code:
cat /tmp/lvols.txt |while read line
do
if [[ $line == rootvg: || $line == LV ]]
then
continue
else
lslv -m $line
fi
done


NOTE: lslv -m will display LP numbers (all of them for the lv) sample output below of non-mirrored logical volume

Code:
hd3:/tmp
LP    PP1  PV1               PP2  PV2               PP3  PV3
0001  0264 hdisk0
0002  0265 hdisk0
0003  0266 hdisk0
0004  0267 hdisk0
0005  0268 hdisk0


Last edited by radoulov; 03-01-2010 at 11:52 AM.. Reason: Please use code tags!
# 2  
Old 03-01-2010
Something like this:

Code:
lslv -m | awk 'NF < 4'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Count columns that are non-empty per line

The file is similar to the attached. Thousands of columns, delimiter is tab, with many columns containing free text and space separated. I want to get the count of columns with non-empty entries. eg.Col1=10, Col6=5, Col8=1 awk preferred (7 Replies)
Discussion started by: genehunter
7 Replies

2. Shell Programming and Scripting

Count duplicate lines ignoring certain columns

I have this structure: col1 col2 col3 col4 col5 27 xxx 38 aaa ttt 2 xxx 38 aaa yyy 1 xxx 38 aaa yyy I need to collapse duplicate lines ignoring column 1 and add values of duplicate lines (col1) so it will look like this: col1 col2 col3 col4 col5 27 xxx 38 aaa ttt ... (3 Replies)
Discussion started by: coppuca
3 Replies

3. Shell Programming and Scripting

count the unique records based on certain columns

Hi everyone, I have a file result.txt with records as following and another file mirna.txt with a list of miRNAs e.g. miR22, miR123, miR13 etc. Gene Transcript miRNA Gar Nm_111233 miR22 Gar Nm_123440 miR22 Gar Nm_129939 miR22 Hel Nm_233900 miR13 Hel ... (6 Replies)
Discussion started by: miclow
6 Replies

4. UNIX for Dummies Questions & Answers

How to count specific columns and merge with unique ones?

Hi. I am not sure the title gives an optimal description of what I want to do. I have several text files that contain data in many columns. All the files are organized the same way, but the data in the columns might differ. I want to count the number of times data occur in specific columns,... (0 Replies)
Discussion started by: JamesT
0 Replies

5. Shell Programming and Scripting

Count Columns and If less add new column

Hi All, My Input.txt should have always 4 columns in some cases i may not get all the 4columns data. My requirement is if columns as not equal to 4 then append new column delimiter. Input.txt A,1,2 B,1,2,3 C,1 Desired output should be in below format Output.txt A,1,2,... (3 Replies)
Discussion started by: kmsekhar
3 Replies

6. Shell Programming and Scripting

Difference between two columns and count

hi I am very new to shell scripting. i wanted to achieve this.. Col1 Col2 Col3 Col4 aa 23 bb 32 aa 34 bb 12 aa 45 bb 345 kk 20 ss 50 kk 30 ss 50 tt 10 vv 50 Desired output is Col1 Col2 Col3 Col4 Difference Count aa 23 bb ... (1 Reply)
Discussion started by: empyrean
1 Replies

7. Shell Programming and Scripting

Count all columns in a given file

Hi, I have a file where i have dump of a DB. it has all the columns and rows inside that. I wanted to extract the columns and number of columns from that dump. Any suggestions will be helpful. Thanks (1 Reply)
Discussion started by: namishtiwari
1 Replies

8. Shell Programming and Scripting

Count minimum columns in file

Hi All, Consider the file with following lines: 1,2,3,4 1,2,3, 5,6,7,7,8,9 1 I need to get the count of minimum columns per line. i.e. in above case, it should come out to be 1 since the last line only has 1 column. I tried following code: minCount = 0 wordCountPerLine = 0... (12 Replies)
Discussion started by: sh_kk
12 Replies

9. Shell Programming and Scripting

Count first column on the basis of two other columns

Hello, I have a file ================= 12 SRV1 GRP1 19 SRV1 GRP1 19 SRV1 GRP2 3 SRV1 GRP1 3 SRV1 GRP2 30 SRV1 GRP2 7 SRV1 GRP1 8 SRV1 GRP3 =========== I want output like =============== 41 SRV1 GRP1 52 SRV1 GRP2 8 SRV1 GRP3 (1 Reply)
Discussion started by: kaustubh137
1 Replies
Login or Register to Ask a Question