Reputation: 55
File: /etc/newsyslog.conf
I am trying to replace the 3rd column (the count column) of each line. It appears as though the first and second columns are separated by tabs. However, the second and third columns are separated by spaces.
I can get the value of the third column, for each line, via:
grep /var /etc/newsyslog.conf | cut -d ' ' -f 3
However, I am having trouble setting/replacing the value in the third column. The problem is that I don't know what the value of the third column will be for any given line. That makes it difficult, using any method I know, to search/replace that specific (third column) value/string.
Thanks for any help or advice you may be able to offer.
edit: I should have mentioned that is a Mac OS 10.6 system.
Upvotes: 2
Views: 975
Reputation: 784998
Better to use awk here to avoid multiple commands:
awk '/\/var/{print $3}'
EDIT:
awk 'BEGIN{OFS="\t"} /\/var/{$3="14"}1' /etc/newsyslog.conf > temp
mv temp /etc/newsyslog.conf
Upvotes: 2