SED mogą pewne rzeczy o wiele łatwiej



Jeśli masz Linux-a i nie kiedykolwiek korzystała z sed (stream editor) tracisz na wielkim narzędzia automatyzacji. Uratowałem się prawdopodobnie 20 godziny ręcznego edycji z około godzinę pracy dwa razy dzisiaj. Hereâ € ™ s jak…. over on the North Carolina Genealogy site I was opening forums for each county in the state of North Carolina (100 counties.) Teraz, I could have gone through and typed out a description, slug (adres) and name for each one, but that looked too tedious. Tak…


I copied and pasted the list of counties to a text file (there was a carriage return after each) so I had one per line. Then I made a second file which I used tr to convert from upper case to lower case (since I wanted lower caseslugs”) I then went through and used sed to convert a space to an underscore. Teraz, I could have done this by hand because the only county with a space in the name is New Hanover, ale…. it was easy as the following

cat county_lowercase.txt | sed 's/ /_/' > county_lowercase_nospace.txt

Tak, the next step was crafting the slugs

cat county_lowercase_nospace.txt | sed 's/$/-county-nc-genealogy-queries/' > slugs.txt

I checked the forum list table for my forum software through phpmyadmin and it was a pretty simple structure, o 8 fields…. a unique id which I set to NULL in my database, forum name, description, slug, forum order, number of posts, number of topics…. I set the last two to 0 throughout (100 lines), the forum order I started a bit past the current forum order numbers that were listed in the current database and I copied and pasted from the textfile the slugs.

Tak, next I crafted the forum titles….

cat county_list.txt | sed 's/$/ County, NC Genealogy Query Forum/' > forum_titles.txt

I oczywiście, those get copied and pasted into the correct column. Przy okazji, the $ above tells sed to put the text at the end of each line so that the county name comes first.

Then the descriptions, again I cut and paste and things look good. From the spreadsheet now I export to csv and import via phpmyadmin and check, lo and behold I now have 100 forums correctly added.

The other big thing though was a script I use to retrieve Kanały RSS. Each page was to have one uniquely named that would be included via a php include call in the page.

Tak… again sed to the rescue.

#!/bin/bash
for name in `cat county_lower_nospace.txt`;
do
cat template_gen.php | sed "s/template_search/$name+county%22+nc/" > "$name"_gen.php
done

VERY easy and it worked like a charm…. 100 php scripts created, one for each county in …. 5 sekund? Ładny.

Finally to top things off, I used sed to make the links to insert in to the pagesagain all 100. Tak, it turned into a simple copy paste for each one.

Thanks sed.. I don’t know how else I could have done this that didn’t involve hours of menial/tedious editing.

For more information on some of the neat textfile tricks you can do with sedtake a look at this sed guide.

Podobne posty

Blog Traffic Exchange Podobne posty
  • Link Directory PHP i menu Importowanie Walczyłem dziś wieczorem z katalogu PHP link. Miałem listę adresów chciałem dodać luzem i udało się powiesić razem poprawny format pliku csv do importu. To dość długa historia, zaczęło się rysia dumpingu źródło w internecie ......
  • 2-sze podróż zaczyna ... Mandriva 2006 uaktualnić 2 - Część 1 Piszę to z laptopem. Po uruchomić Mandrivę 2006 bez prawdziwych uderzeń istotnych dla kilku tygodni Doszedłem do punktu, w którym jestem gotowa się zanurzyć na pulpicie. Pulpit jest moim podstawowym stacja robocza. Laptop get okazjonalne wykorzystanie światła i jest jednym ......
  • Idealny Mandriva 2006 ustawienie (dla ISP i hostingowych) Jak do podrobienia ma co opisywać jak kopiowanie i wklejanie, jak-to się na idealny instalacji dla Mandrivy 2006 do potrzeb ISP i serwisów hostingowych. To copy-paste, ponieważ sugerują, kopiowanie i wklejanie ich polecenia do putty / xterm / console okna na maszynie, że jesteś konfigurowania .......
Blog Traffic Exchange Podobne Strony
  • FaxFreeCash Get the CASH you NEED Today... Without the Paperwork! Here at FaxFreeCash.com we understand that YOUR time is valuable! That's why we launched FaxFreeCash.com, our convenient, paperless cash advance loan finding service and YOUR one-stop online shop for finding a same-day cash advance. Ze względu na nasze unikatowych wielokrotnego pożyczkodawcy ......
  • 3 Ways to Determine Gold Coin Prices There are many different kinds of coins you can collect. You can collect the standard coins which are distributed throughout society. You can also collect all of the commemorative coins which are designated to pay respects to the different states, Apollo 11, Presidents and more. One of the oldest and......
  • Databazaar.com Gold-Printer Accessories Buy $75 in Original HP ink cartridges and receive a $15 Shell Gift Card!!! AND Buy two Original HP LaserJet print cartridges and receive a $30 Darden gift card of your choice!!! Timeframe • April 1 – June 30, 2011 at databazaar.com. Ranked in 2006 by Internet Retailer as the......
en.pdf24.org    Wyślij artykuł jako PDF   

Podobne wiadomości


Zobacz, co stało się to dzień w historii z albo BBC Wikipedia
Szukaj:
Słowa kluczowe:
Amazon Logo

Komentarze są zamknięte.


Przełącz na naszej stronie WAP