I have to often make changes to configuration files such as httpd.conf and squid.conf . Man ir bieži mainīt konfigurācijas failus, piemēram, httpd.conf un 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. Šie faili ir daudz līniju, kas komentēja, kas, galvenokārt piezīmes un daži iespējamās konfigurācijas direktīvām, ir piezīmes veic kā tie nav vajadzīgi pēc noklusējuma. 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. Problēma man sejas rediģēšanas laikā šādas lietas ir tas, ka ir tik daudz rindu komentēja, ka man ir nepieciešams, lai ritinātu neskaitāmas pozīcijas pirms es varētu atrast nākamo aktīvā konfigurācijas direktīva. I found a fine solution to help me out with this. Es atklāju soda risinājumu, lai man palīdzēt ar to.
I now use the following command when I want to just look at the active directives in the Apache configuration file: Es tagad var izmantot šādu komandu, kad es vēlos tikai apskatīt darbojas direktīvu Apache konfigurācijas failu:
# 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. Šī komanda skan failu / etc / httpd / conf / httpd.conf un filtri visus komentārus un papildu baltās telpas, atstājot tikai aktīvās konfigurācijas uzstādījumus. This makes it very easy for me to look at the configuration file. Tāpēc ir ļoti viegli man apskatīt konfigurācijas failu.
If you want to just filter out the lines that begin with comments run the following command: Ja jūs vēlaties vienkārši izfiltrēt līnijas, kas sākas ar komentāriem palaist šādu komandu:
# 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. Tas ir diezgan daudz pašu komandu, kā agrāk, nelielas izmaiņas. The first * is replaced by ^ , which is regex for beginning of line. Pirmā * aizstāj ^, kas ir regex uz sākuma līnijas.























{ 1 trackback } (1 Trackback)
{ 4 comments… read them below or (4 comments ... lasīt tos zem vai add one pievienot vienu } )
Your command to show a file without comments could be very useful for me. Savu komandu, lai parādītu failu bez komentāriem varētu būt ļoti noderīga mani.
However, when I tried to run Taču, kad es centos palaist
# sed '/ ^#/d; /^ *$/d' /boot/grub/menu.lstI get this error I 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. Jāatzīmē, ka es kopēt / ielīmēt komandu tieši no sava amata.
I have a feeling this may be a HTML-related problem. Man ir sajūta, tas var būt HTML-saistītu problēmu.
Any clues? Jebkurš clues?
Thanks Pateicība
Paul Paul
Well, after a bit of searching around, I found that this command does what I want Nu, pēc meklēšanas ap bit, es atklāju, ka šī komanda nav tas, ko es gribu
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 Joprojām nav pārliecināts, ko tieši's wrong with komandu dots rakstā, bet tā varētu būt, ka HTML ir savā ziņā "izkropļots" pirmais singls citātu zīmes
After a little more experimentation, I find that the command below does what the command in the article was intended to do Pēc nedaudz vairāk eksperimentu, es uzskatu, ka komanda zem dara komandu pantā bija paredzēts, lai do
sed '/^#/d; /^*$/d' /path/to/file/hi, is this the same as: hi, tas pats kā:
grep -v '#' file grep-v '#' file
Leave a Comment Leave Comment