I have to often make changes to configuration files such as httpd.conf and squid.conf . Я повинен часто вносити зміни в конфігурацію файлів, таких як httpd.conf і squid.conf. These files have a large number of lines that are commented out, mostly comments and some possible configuration directives that have been commented out as they are not required by default. Ці файли мають велику кількість рядків, які закоментовані, в основному зауваження та деякі можливі конфігурації директивами, які були закоментовані як вони не зобов'язані за замовчуванням. A problem I face while editing such files is that there are so many lines commented out that I need to scroll down many lines before I can find the next active configuration directive. Проблема я особа при редагуванні таких файлів є те, що існує так багато ліній коментує, що мені потрібно прокручувати багато ліній, поки я зможу знайти наступну директиву активної конфігурації. I found a fine solution to help me out with this. Я знайшов прекрасне рішення, яке допоможе мені з цим.
I now use the following command when I want to just look at the active directives in the Apache configuration file: Зараз я використовую наступну команду, коли я хочу просто подивитися на активну директив у файлі конфігурації Apache:
# sed '/ *#/d; /^ *$/d' /etc/httpd/conf/httpd.conf Sed # '/ * # / D; / ^ * $ / D' / ETC / HTTPD / CONF / httpd.conf
This command reads the file /etc/httpd/conf/httpd.conf and filters out all the comments and extra white spaces, leaving just the active configuration settings. Ця команда читає файл / ETC / HTTPD / CONF / httpd.conf і відфільтровує всі зауваження і додаткові пробіли, залишаючи тільки активні параметри конфігурації. This makes it very easy for me to look at the configuration file. Це робить його дуже легким для мене подивитися на конфігураційний файл.
If you want to just filter out the lines that begin with comments run the following command: Якщо ви просто хочете відфільтрувати рядки, які починаються з коментарями запустіть наступну команду:
# sed '/ ^#/d; /^ *$/d' /etc/httpd/conf/httpd.conf Sed # '/ ^ # / D; / ^ * $ / D' / ETC / HTTPD / CONF / httpd.conf
It's pretty much the same command as earlier with a small change. Це майже та ж команда, як раніше з невеликою зміною. The first * is replaced by ^ , which is regex for beginning of line. * Перша замінена ^, що регулярні вирази для початку лінії.























{ 1 trackback } (1) Архів
{ 4 comments… read them below or (4 комментария ... читати їх нижче або add one Додати одну } )
Your command to show a file without comments could be very useful for me. Ваша команда, щоб показати фото без коментарів можуть бути дуже корисні для мене.
However, when I tried to run Однак, коли я спробував запустити
# sed '/ ^#/d; /^ *$/d' /boot/grub/menu.lstI get this error Я отримую таку помилку
sed: -e expression #1, char 1: unknown command: ` 'bash: /^: No such file or directoryNote that I copied/pasted the command directly from your post. Зауважте, що я скопіював / вставив команду прямо з Вашого повідомлення.
I have a feeling this may be a HTML-related problem. Мені здається, це може бути HTML-пов'язані проблеми.
Any clues? Будь-які ключі?
Thanks Спасибо
Paul Поле
Well, after a bit of searching around, I found that this command does what I want Ну, після трохи пошуків навколо, я виявив, що ця команда робить те, що я хочу
sed '/^#/ d' /boot/grub/menu.lst>/boot/grub/menu.newStill not sure exactly what's wrong with the command given in the article, but it might be that the HTML has somehow 'distorted' the first single quote mark Чи не впевнені, що саме те, що трапилося з командою наведені в статті, але це може бути те, що HTML якось 'спотвореного "першого єдиного знака цитатою
After a little more experimentation, I find that the command below does what the command in the article was intended to do Через трохи більше експериментів, я вважаю, що нижче команда робить те, що команда в статті, була покликана зробити
sed '/^#/d; /^*$/d' /path/to/file/hi, is this the same as: Привіт, це так само, як:
grep -v '#' file Grep-# 'у файлі'
Leave a Comment Залишити коментар