DB 관련해서 질문드립니다.

karistuck의 이미지


아래와 같은 줄이 200줄 가까이 있습니다. VALUES(160, 47, 이부분을 수정하려고 합니다.

INSERT INTO `jos_views_fieldoptions` VALUES(160, 47, '네덜란드', '네덜란드', 'netherlands.png', 1);
INSERT INTO `jos_views_fieldoptions` VALUES(161, 47, '네팔', '네팔', 'nepal.png', 2);
INSERT INTO `jos_views_fieldoptions` VALUES(162, 47, '노르웨이', '노르웨이', 'norway.png', 3);
INSERT INTO `jos_views_fieldoptions` VALUES(163, 47, '뉴질랜드', '뉴질랜드', 'new-zealand.png', 4);
INSERT INTO `jos_views_fieldoptions` VALUES(164, 47, '덴마크', '덴마크', 'denmark.png', 5);
INSERT INTO `jos_views_fieldoptions` VALUES(165, 47, '독일', '독일', 'germany.png', 6);
INSERT INTO `jos_views_fieldoptions` VALUES(166, 47, '라오스', '라오스', 'laos.png', 7);
INSERT INTO `jos_views_fieldoptions` VALUES(167, 47, '러시아', '러시아', 'russia.png', 8);
INSERT INTO `jos_views_fieldoptions` VALUES(168, 47, '레바논', '레바논', 'lebanon.png', 9);
INSERT INTO `jos_views_fieldoptions` VALUES(169, 47, '루마니아', '루마니아', 'romania.png', 10);
INSERT INTO `jos_views_fieldoptions` VALUES(170, 47, '리비아', '리비아', 'libya.png', 11);
INSERT INTO `jos_views_fieldoptions` VALUES(171, 47, '말레이시아', '말레이시아', 'malaysia.png', 12);
INSERT INTO `jos_views_fieldoptions` VALUES(172, 47, '멕시코', '멕시코', 'mexico.png', 13);
INSERT INTO `jos_views_fieldoptions` VALUES(173, 47, '모나코', '모나코', 'monaco.png', 14);

------------------------------------------------------------------------------------

VALUES(403, 83,
VALUES(404, 83,
VALUES(405, 83,
VALUES(406, 83,
VALUES(407, 83,

이렇게 앞자리 숫자는 순서대로 변하게 하고 뒷자리 숫자는 동일하게 바꾸려고 합니다. 200여개국이 되는데 이거 하나씩 바꿀생각은 하니 숨이 턱턱 막혀서 혹시 고수분들이 이런식의 작업을 좀 쉽게 바꿀수 있는 팁/테크 를 전수받아 사용해보고 싶어 이렇게 질문드렸습니다.

감사합니다 좋은시간되세요~

Prentice의 이미지

뒤의 숫자 고치기: vim에서 파일을 열고 :%을 눌러 다음과 같이 입력합니다.

:%s/\(VALUES([0-9]\+\), 47,/\1, 83,/

앞의 숫자는 어떻게 하시려는 건가요? 모든 솟자에 243을 더하시려는 건가요? 그렇다면 vim에서 파일을 열고 :%을 눌러 다음과 같이 입력합니다. ^a에서 컨트롤 에이를 누르시면 됩니다.
:%normal 243^a

단, 윈도용 vim의 기본 설정에서는 컨트롤 에이가 안 먹힐 것입니다.

aero의 이미지

sql.txt

INSERT INTO `jos_views_fieldoptions` VALUES(160, 47, '네덜란드', '네덜란드', 'netherlands.png', 1);
INSERT INTO `jos_views_fieldoptions` VALUES(161, 47, '네팔', '네팔', 'nepal.png', 2);
INSERT INTO `jos_views_fieldoptions` VALUES(162, 47, '노르웨이', '노르웨이', 'norway.png', 3);
INSERT INTO `jos_views_fieldoptions` VALUES(163, 47, '뉴질랜드', '뉴질랜드', 'new-zealand.png', 4);
INSERT INTO `jos_views_fieldoptions` VALUES(164, 47, '덴마크', '덴마크', 'denmark.png', 5);
INSERT INTO `jos_views_fieldoptions` VALUES(165, 47, '독일', '독일', 'germany.png', 6);
INSERT INTO `jos_views_fieldoptions` VALUES(166, 47, '라오스', '라오스', 'laos.png', 7);
INSERT INTO `jos_views_fieldoptions` VALUES(167, 47, '러시아', '러시아', 'russia.png', 8);
INSERT INTO `jos_views_fieldoptions` VALUES(168, 47, '레바논', '레바논', 'lebanon.png', 9);
INSERT INTO `jos_views_fieldoptions` VALUES(169, 47, '루마니아', '루마니아', 'romania.png', 10);
INSERT INTO `jos_views_fieldoptions` VALUES(170, 47, '리비아', '리비아', 'libya.png', 11);
INSERT INTO `jos_views_fieldoptions` VALUES(171, 47, '말레이시아', '말레이시아', 'malaysia.png', 12);
INSERT INTO `jos_views_fieldoptions` VALUES(172, 47, '멕시코', '멕시코', 'mexico.png', 13);
INSERT INTO `jos_views_fieldoptions` VALUES(173, 47, '모나코', '모나코', 'monaco.png', 14);

Perl one-liner
특정숫자부터 1씩 증가시키려면

perl -pe 'BEGIN{$n=403} s/VALUES\((\d+), (\d+)/VALUES\($n, 83/; $n++' sql.txt

원래 값에 특정값을 더하는 식으로 하려면
perl -pe 's/VALUES\((\d+), (\d+)/"VALUES(".($1+243).", 83"/e' sql.txt

결과

INSERT INTO `jos_views_fieldoptions` VALUES(403, 83, '네덜란드', '네덜란드', 'netherlands.png', 1);
INSERT INTO `jos_views_fieldoptions` VALUES(404, 83, '네팔', '네팔', 'nepal.png', 2);
INSERT INTO `jos_views_fieldoptions` VALUES(405, 83, '노르웨이', '노르웨이', 'norway.png', 3);
INSERT INTO `jos_views_fieldoptions` VALUES(406, 83, '뉴질랜드', '뉴질랜드', 'new-zealand.png', 4);
INSERT INTO `jos_views_fieldoptions` VALUES(407, 83, '덴마크', '덴마크', 'denmark.png', 5);
INSERT INTO `jos_views_fieldoptions` VALUES(408, 83, '독일', '독일', 'germany.png', 6);
INSERT INTO `jos_views_fieldoptions` VALUES(409, 83, '라오스', '라오스', 'laos.png', 7);
INSERT INTO `jos_views_fieldoptions` VALUES(410, 83, '러시아', '러시아', 'russia.png', 8);
INSERT INTO `jos_views_fieldoptions` VALUES(411, 83, '레바논', '레바논', 'lebanon.png', 9);
INSERT INTO `jos_views_fieldoptions` VALUES(412, 83, '루마니아', '루마니아', 'romania.png', 10);
INSERT INTO `jos_views_fieldoptions` VALUES(413, 83, '리비아', '리비아', 'libya.png', 11);
INSERT INTO `jos_views_fieldoptions` VALUES(414, 83, '말레이시아', '말레이시아', 'malaysia.png', 12);
INSERT INTO `jos_views_fieldoptions` VALUES(415, 83, '멕시코', '멕시코', 'mexico.png', 13);
INSERT INTO `jos_views_fieldoptions` VALUES(416, 83, '모나코', '모나코', 'monaco.png', 14);
sisuc의 이미지

sql에서 csv로 뽑은 다음에 엑셀로 불러들여 필요한부분 지우고 쿼리로 대체한다음

바꿀부분에 맨위에 400으로 넣은다음 +로 끝까지 긁은 다음

쿼리를 복사, 붙여넣기 하면 안될까요..?ㅎㅎ

위대한 한글

위대한 한글

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.