Saturday 15 September 2012

bash - How To Eliminate Duplicate Results? -


I have written a bash script to check / etc / fstab, fsck option (last column)

Enable <1> for <1> - 0 - disable

1 - $ (cat / etc / fstab | grep -v 'proc')

  # ! / Bin / bash | Sda \ | Rootvg \ | Sysfs \ | Debugfs \ | Fd0 \ | .host \ | Nfshome: \ | Devpts' | Awk '{print $ 6}'); Do $ for n (cat / etc / fstab | grep -v 'proc \ | sda \ | rootvg \ | sysfs \ | debugfs \ | fd0 \ | .host \ | nfshome: \ | devpts' | awk' {print $ 1} '); What to do [["$ i"! = "0"]]; Then check "$ n = FSKK non-OS filesystem error" !!! Else echo "non-OS Partiton FSC successfully complained !!!" Finished  

Output:

  / dev / repovg / lvol1 = FSKC check on non-OS file system error !!! / Dev / appvg / appvol-os = FSCK probe on non-OS file system error !!! / Dev / TEST12 / TEST12 = FSCK check on non-OS filesystem error !!! / Dev / repovg / lvol1 = FSCK probe on non-OS filesystem error !!! / Dev / appvg / appvol-os = FSCK probe on non-OS file system error !!! / Dev / TEST12 / TEST12 = FSCK check on non-OS filesystem error !!! / Dev / repovg / lvol1 = FSCK probe on non-OS filesystem error !!! / Dev / appvg / appvol-os = FSCK probe on non-OS file system error !!! / Dev / TEST12 / TEST12 = FSCK check on non-OS filesystem error !!!  

Is there a way to eliminate duplicate values?

I can try

sh + x script.sh | Sort-U

But, can I do anything in script?

You should not use nested loops at all. Try something like this in Awk:

  awk '! / Proc | Sda | Rootvg | Sysfs | Debugfs | Fd0 |. Hosting | Nfshome: | Devpts / {if ($ 6! = 0) print $ 1, "= FSCK checks on non-OS filesystem error!" Other print "non-OS Partiton FSC successfully complained!" } / Etc / fstab  

This will be done by typing lines from lines with regular expression (as in your grep) by line / etc / fstab < / Code> reads via line ). For those rows that do not match, it checks the 6th column and prints one of the two messages, depending on the value.

On one side, . in .host means "any character", so you should save it from . If it means literal . or consider removing it completely.


No comments:

Post a Comment