more useful options | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Fellow monks I am building an application that should read and collect data from many NetApp filers and store them in a database for making periodical usage reports. To avoid bothering production filers during the early stage of development I created a file for each filer containing the output of the quota report command. The output looks like:
To simulate the command output, I'd need to read the file line by line, print if it doesn't begin with tree, otherwise substitute the fifth field (say: $field[4] with int rand $field[4]). Since the dashed line on top of the report gave me an hint for creating a sprintf format, I found that this one-liner just does the job I need: perl -pe 'next unless /^tree/ ; @f=split ; $f[4] = int rand $f[4] ; $_ = sprintf "%-5s %8d %-8s %-8s %8d %8d %7d %7d %-15s\n",@f' filer.quota.reportBut what if I hadn't any hint? How would you replace the fourth field leaving the line formatting in a sane state? Thanks in advance for your suggestions Ciao! In theory, there is no difference between theory and practice. In practice, there is. In reply to changing a portion of a line leaving its formatting intact by bronto
|
|