Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am writing script that reclaim storage that is mapped behind FAs. I am stuck on this step. I can read the first field of each line to execute a command or take up to 12 lines of field1 separated by a comma (,) and run command. U can see the diff.
My input file is file1.out and has this:
0011 Not Visible ***:* 02B:C0 2-Way Mir N/Grp'd RW 668
0013 Not Visible ***:* 08B:C0 2-Way Mir N/Grp'd RW 668
0014 Not Visible ***:* 01B:C0 2-Way Mir N/Grp'd RW 668
0015 Not Visible ***:* 02A:C0 2-Way Mir N/Grp'd RW 668
007F Not Visible ***:* 01B:D1 2-Way Mir N/Grp'd (M) RW 51789
0085 Not Visible ***:* 10A:D5 2-Way Mir N/Grp'd RW 8632
0086 Not Visible ***:* 07A:D0 2-Way Mir N/Grp'd RW 8632
0087 Not Visible ***:* 10B:D3 2-Way Mir N/Grp'd RW 8632
0088 Not Visible ***:* 16B:D2 2-Way Mir N/Grp'd RW 8632
0089 Not Visible ***:* 07B:CA 2-Way Mir N/Grp'd (M) RW 17263
008B Not Visible ***:* 07A:DA 2-Way Mir N/Grp'd (M) RW 17263
008D Not Visible ***:* 07B:D1 2-Way Mir N/Grp'd (M) RW 17263This file can be hundred of lines.
I want an output that lookslike this:
0011,0013,0014,0015,007F,0085,0086,0087
0088,0089,008B,008D,008F,0093,0097009F
00E3,013A ,0140,0162,017D,0188,018B
so my command then will read each line as a parameter like this:symmaskdb -sid xxxx list assign -dev < line generated above >
Any help I would appreciate.
I am onlble to print all field1 in a single line. like this: awk '{printf("%s,",$1) }' vlud.out
Btw this is not homework. Just want to simplify my daily routines at work.
Thanks.

I am not certain of your requirements concerning how many arguments should print. This script accepts a variable:#!/bin/ksh norec=$(wc -l < vlud.out) awk ' { if(NR % cnt == 0 || NR == myrec) printf("%s\n",$1) else printf("%s,",$1) } ' cnt=7 myrec="$norec" vlud.out

Nail - one more thing in this logic. Now dumpued it in a file but the last character in the file is , as you can see in output.
0011,0013,0014,0015,007F,0085,0086
0087,0088,0089,008B,008D,008F,0093
0097,009F,00E3,013A,0140,0162,017D
0188,018B,019E,01AA,01B1,01B6,01BC
01BD,01BE,01BF,01C0,01C1,01C2,01C3
01D9,01DA,01DB,01DC,032A,0330,0336
0370,0509,050A,055B,Any way using sed to remove that last , at the end last line?
Thanks

For some reason, the solaris/sun version of awk is not passing the 2nd variable, norec, correctly. It looks like a bug. Change to nawk, and the script appears to work:
#!/bin/ksh norec=$(wc -l < vlud.out) nawk ' { if(NR % cnt == 0 || NR == myrec) printf("%s\n",$1) else printf("%s,",$1) } ' cnt=7 myrec="$norec" vlud.outCheck out this link on how to pass shell variables to awk:
http://www.tek-tips.com/faqs.cfm?fi...
BTW, sed can remove the last comma of the last line of a
file:sed '$s/,$//' datafile

![]() |
Remove 'blanks' in a file...
|
how to fetch the fileds f...
|
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |