'Code Snippets'에 해당되는 글 7건

  1. 2009.05.21 워드에서 정규식 쓰기 1
  2. 2009.04.12 기본 리눅스/유닉스
  3. 2008.01.15 [HTML] <SELECT> <OPTION>
  4. 2007.02.09 전처리기 오퍼레이터 정리 1
  5. 2007.02.03 부분 문자열 가져오기. 2
  6. 2007.01.04 C 에서 goto 사용하기. 2
  7. 2006.07.07 색상표

워드에서 정규식 쓰기

|

 

원문: http://office.microsoft.com/en-us/help/HA010873041033.aspx


The examples on this reference page show you some of the ways that you can use wildcard characters and regular expressions in Microsoft Word. For an introduction to this subject, see Add power to Word searches with regular expressions.

Example 1: Transpose names with middle initials

The article Add power to Word searches with regular expressions explained how to use wildcard characters and a regular expression to transpose names—for example, to change "Colin Wilcox" to "Wilcox, Colin." But what do you do if some or all of the names contain middle initials or middle names? This example uses a combination of wildcard characters and character codes to transpose names that contain middle initials. If you're unfamiliar with character codes, see the Word Help topic titled "Find and replace text or other items."

Keep these facts in mind as you proceed:

  • Whenever you use this expression on names that reside in a table, you must first convert that table to text.
  • If the table contains more than one column, copy the column containing the names to a blank document and convert it to text there.
  • After you transpose the names, convert the text back to a table. You can then delete the original column and replace it with your changed data.

Follow the steps in these examples to walk through the entire process.

To prepare sample data
  1. If you haven't already done so, start Word and create a new, blank document.
  2. Insert a blank table into the document. Make the table one column wide by four rows high.
  3. Copy these names individually, and paste each one into a blank table cell: Joshua Quentin Barnhill
    Doris X. Hartwig
    Tamara Y. Johnston
    Daniel Shimshoni
    Your table should look something like this:

    Joshua Quentin Barnhill
    Doris X. Hartwig
    Tamara Y. Johnston
    Daniel Shimshoni

  4. Select the table, and on the Table menu, point to Convert, and then click Table to Text.
  5. Select Paragraph marks as the text separator, and then click OK.
To transpose names with initials
  1. On the Edit menu, click Find to open the Find and Replace dialog box.
  2. Select the Use wildcards check box (you may need to click More to see the check box), and then enter the following expression in the Find what box: (*) ([! ]@)^13
  3. Enter the following expression in the Replace with box: \2, \1^p Make sure you enter a space between the two sets of parentheses and after the exclamation point. If you haven't seen the ^13 character before, we explain what it does in the next section.
  4. Select the list of names, and then click Replace All. Word transposes the names and either middle initials or middle names, like so:

Barnhill, Joshua Quentin
Hartwig, Doris X.
Johnston, Tamara Y.
Shimshoni, Daniel

To convert the changed text back to a table
  1. Select the list of transposed names.
  2. On the Table menu, point to Convert, and then click Text to Table. The Convert Text to Table dialog box opens.
  3. Under Separate text at, click Paragraphs, and then click OK.

The expressions dissected

Let's look at the individual pieces of the expression to see how they work, starting with the second half of the expression in the Find what box.

The entire expression looks for two groups of patterns: a first name with a middle initial (or a middle name) and a last name. This part of the expression matches the last names:

([! ]@)^13

We need to know where the last name ends, so we also use the ^13 character to search for the paragraph mark at the end of each line. However, since we don't plan to reuse the paragraph mark, we surround everything else with parentheses.

You can try this by copying the names to your test document again (make sure you separate them with paragraph marks), and then search using ([! ]@)^13 in the Find what box. Search matches each last name.

Because search starts again at the beginning of the next line, we use the asterisk wildcard character (*) to match everything from there to the beginning of the next last name.

Since we don't plan to reuse the space in front of the last name, we use parentheses to exclude it from the two groups:

(*) ([! ]@)^13

 Important   Be careful when using the ^13 character code. Normally, you can use the ^p character code to search for paragraph marks. However, that code does not work in wildcard searches. Instead, you need to use the substitute code ^13. Although the ^p character code does not work in wildcard searches, you should use it in wildcard replace operations. Why? The ^p character includes formatting information, and the ^13 character does not. In addition, you cannot assign style information to the ^13 character at all. Misusing the ^13 code in a replace operation can essentially convert your document into a file that you cannot format.

In the Replace with box, the \2, characters tell search to write the second pattern first and to add a comma after the pattern. The \1^p characters tell search where to write the first pattern and to write a paragraph mark after that pattern.

Example 2: Transposing dates

You can use the regular expressions shown here to convert dates in European format to dates in the U.S. format.

To transpose dates
  1. Copy and paste the following date into your document: 28th May 2003
  2. Open the Find and Replace dialog box, and enter the following expression in the Find what box: ([0-9]{1,2})([dhnrst]{2}) (<[ADFJMNOS]*>) ([0-9]{4}) Make sure you insert a space between the following opening and closing parentheses: 2}) (<[ and *>) ([0.
  3. Enter the following expression in the Replace with box (make sure you insert a space between each set of characters), and then click Replace All: \3 \1, \4

    Search replaces 28th May, 2003 with May 28, 2003.

The expression, piece by piece

Let's start with the expression in the Find what box. The expression works by breaking dates down into four patterns, denoted by the sets of parentheses. Each pattern contains the components that you find in all dates written in the style that you used in the example. Working from left to right:

  • The number range [0-9] matches the single-digit numbers in the first pattern. Because dates can consist of two numbers, we tell search to return either one-digit or two-digit dates: {1,2}. The result is the first pattern: ([0-9]{1,2}).

    Ordinals make up the second pattern. Ordinals consist of "th," "nd," "st," and "rd," so we add those letters to a range [dhnrst]. Because ordinals always consist of two letters, we restrict the letter count to two: ([dhnrst]{2}).

  • Next comes a space, followed by literal and wildcard characters that find month names. All month names begin with these capital letters: ADFJMNOS. We don't know how many characters follow each capital letter, so we follow them with the asterisk (*). We're only interested in the month name itself, so we use greater-than and less-than characters to limit the results to the individual word. The result is the fourth pattern: (<[ADFJMNOS]*>).
  • Finally, we search for the year. We use the same number range, but this time we restrict the count to four letters ([0-9]{4}).

In the Replace with box, notice that we only wrote three of the four address patterns. We omitted the ordinal (the "th") from the date because dates in the U.S. format don't use ordinals. If you want to leave the ordinal in the date, enter \3 \1\2, \4 in the Replace with box. In this case, you enter a space both after the 3 and after the comma, nowhere else.

At this point, you may ask how to handle dates in which the name of the month isn't spelled out, such as 28/05/03. You search using this expression:

([0-9]{1,2})/([0-9]{1,2})/([0-9]{2})

You replace using this expression:

\3/\1/\2

If the date takes the format of 28/05/2003, you use {4} in the last pattern instead of {2}.

About using list separators in regular expressions

The previous example uses the following argument to find either one-digit or two-digit dates: {1,2}. In this case, a comma separates the two values. However, remember that your regional settings in Microsoft Windows® control the list separator that you use. If your regional settings specify the use of semicolons as list separators, you must use them instead of commas.

To find out which list separator your operating system specifies
  1. Click Start, point to Settings, and then click Control Panel.
  2. Double-click Regional Settings (if you use Windows Me, Windows 98, or Windows NT®), Regional Options (if you use Windows 2000), or Regional and Language Options (if you use Windows XP).

     Note   If you use Category view in Windows XP, you only need to click Regional and Language Options once.

The following table describes how to find the list separator setting for the supported versions of Windows.

Operating System Steps to find your list separator
Windows XP
  1. After you click or double-click the Regional and Language Options command, the Regional and Language Options dialog box opens. On the Regional tab, click Customize. The Customize Regional Options dialog box opens.
  2. Click the Numbers tab, and then locate the List separator entry.
Windows 2000
  1. After you double-click the Regional Options command, the Regional Options dialog box opens.
  2. Click the Numbers tab, and then locate the List separator entry.
Windows Me, 98, and NT
  1. After you double-click the Regional Settings command, the Regional Settings dialog box opens.
  2. Click the Numbers tab and locate the List separator entry.

Example 3: Add periods to, or remove them from, salutations

In some countries, honorific titles (Mr., Mrs., and so on) do not include periods. This example shows you how to add periods to or remove them from honorifics. From this point on, we assume that you know how to use the Find and Replace dialog box.

This expression finds Mr, Ms, Mrs, and Dr without periods:

<([DM][rs]{1,2})( )

Notice that the expression uses a second pattern containing a blank space. That space normally would follow the honorific if the period was not there. This expression adds the period:

\1.\2

To do the reverse, search using this expression:

<([DM][rs]{1,2}).

And replace using this expression:

\1

Example 4: Find duplicate paragraphs or rows

When you use this expression, you may want to sort the list first to place duplicate rows next to each other. Also, you need to remove all blank paragraph marks. In other words, if you use blank paragraphs to separate blocks of text, like so:

Joshua Quentin Barnhill¶

Joshua Quentin Barnhill¶

Doris X. Hartwig¶

you need to remove those paragraphs, like so:

Joshua Quentin Barnhill¶
Joshua Quentin Barnhill¶
Doris X. Hartwig¶

You can use your favorite method to remove the blank paragraphs, but since we're talking about regular expressions, here's one that finds two consecutive paragraph characters. Search using this expression (the @ character repeats the find-and-replace operation and removes all multiple empty lines):

(^13)\1@

You replace the results with this expression:

^p

Now let's look at ways to replace text. This expression finds any sequence of two consecutive identical paragraphs:

(*^13)\1

This expression also matches longer repetitions of text that end in paragraphs. For example, run the expression against the following list:

Joshua Quentin Barnhill¶
Doris X. Hartwig¶
Joshua Quentin Barnhill¶
Doris X. Hartwig¶
Tamara Y. Johnston¶

Search finds the first four lines and stops only when the overall pattern changes. In contrast, if you run the expression against this list:

Joshua Quentin Barnhill¶
Joshua Quentin Barnhill
Doris X. Hartwig¶
Doris X. Hartwig¶

The expression finds only the first two paragraphs. 

To search for a greater number of identical items, add more placeholders. For example, this expression finds three consecutive identical paragraphs:

(*^13)\1\1

You can also use braces to do the same thing. The following examples find two and three identical paragraphs, respectively:

(*^13){2}
(*^13){3}

Or, you can find either two or three identical paragraphs:

(*^13){2,3}

You can also find two or more identical paragraphs:

(*^13){2,}

You can replace any of those expressions with the following string:

\1

In addition, you can repeat the find-and-replace operation as needed to replace all the duplicate paragraphs in your document, or you can add the @ wildcard character and have the expression repeat the operation for you:

(*^13)\1@

You also use this method to replace duplicate rows in a table. To do so, first remove any merged cells, and then sort the table to place duplicate cells adjacent to each other. Next, convert your table to text. (On the Table menu, point to Convert, and then click Table to text; when prompted, use the tab delimiter.) After you make your replacements, convert the text back to a table.

More examples

And

기본 리눅스/유닉스

|
HP_UX> glance
화면 정렬 " O "

* CPU 확인하는 법

/proc/cpuinfo 의 내용 중에 physical id : 0 이 항목이 있습니다. 이것은 CPU 자체의 ID값입니다. 

예를 들어 어떤 서버의 processor 항목이 최대 1까지 있으면 dual 1개만 있던가, single 2개가 꼽혀 있다는 얘긴데 physical id 가 0만 있다면 single 2개가 꼽혀 있다는 얘기로 보면 됩답니다.

또 듀얼/쿼드 코어 CPU에는 core id 라는 항목이 따로 있습니다. 이거 없으면 single 입니다.

가장 간단한 방법은...
싱글/듀얼/쿼드 구분은 core id가 있느냐 없느냐로 판별하면 되고
듀얼/쿼드의 구분은 core id 아래 필드인 cpu cores라는 필드의 값으로 판별하시면 됩니다.

OS
 uname -a
 /etc/redhat-release

 

CPU
 /proc/cpuinfo
 /sbin/dmidecode 

 

internal disk 정보 확인
   cat /proc/scsi/scsi


s/w 미러인 경우
   cat /proc/mdstat  

 

hp장비에서 internal disk raid 정보보기.
cat /proc/driver/cciss/cciss*


And

[HTML] <SELECT> <OPTION>

|
<select>
     <option style="color: white; background-color: blue">a</option>
     <option style="color: white; background-color: red">b</option>
     <option style="color: white; background-color: orange">c</option>
     <option style="color: white; background-color: gray">d</option>
     <optgroup label="구분선">
          <option value="">가</option>
          <option value="">나</option>
          <option style="background-color: #e4ffe5" value="">다</option>
     </optgroup>
</select>


위 코드의 결과




원문: http://mdoli.com/tatter/5
And

전처리기 오퍼레이터 정리

|

http://lagoons.net/tt/481

후리자가 불펌한 걸,

다시 불펌 -_-;


define 쓰지 말라고 백번을 얘기해도 소용없다.

어느새 손은 define 을 치고 있는걸 어찌하리...( -_-)



아참, 이제는 자바 프로그래머였지;;;

And

부분 문자열 가져오기.

|
adadad.afs.1231.qz라는 문자열에서 중간의 1231 을 가져오는 방법.


우선 가장 간단하게 생각할 수 있는 방법.

1. 부분 문자열 가져오기.

STR=adadad.afs.1231.qz
STR=${STR:11:4}

11번째 문자부터 4개를 가져오는 코드이다.

빼오려는 문자열의 길이와 위치가 항상 같다면 이 방법이 제일 간단할 듯.

하지만 숫자가 자리수가 바껴서 길이가 달라지면 저런 방법으로는 할 수 없다.


그래서 패턴을 사용했다.

2. 패턴을 사용해서 중간 값 가져오기.

STR=adadad.afs.1231.qz
STR=${STR%.*}
echo ${STR##*.}

두번째 줄에서 뒤에서부터 처음에 나온 . 이후는 잘라내고,

세번째 줄에서 앞에서부터 마지막에 나온 . 이전을 잘라낸다.


문자열을 잘라내는 다른 방법으로는 IFS(Internal Field Separator) 를 점(.)으로 설정해서,

점(.) 단위로 문자열을 잘라낼 수 있다.

기타. IFS 를 사용해서 반복문을 실행.

STR=adadad.afs.1231.qz
IFS=.
for i in $STR ; do
  echo $i
done
IFS=" "

위의 예제는 . 단위로 문자열을 잘라서 화면에 뿌려주는 예제이다.

....소스를 어디서 주워온지는 잊어버린지 오래이고;;;


자세한 레퍼런스는 귀찮으니 생략;;;

혹시 심심하면 나중에 추가 할 수도~

그리고, 틀렸거나 더 좋은 방법이 있을 수 있으니 있으면 연락 바람 -_-/
And

C 에서 goto 사용하기.

|

나같은 경우에는 C로 프로그래밍을 할 경우에 거의 항상 goto 문을 사용한다.


근데, 항상 주변에서 goto 는 존재 자체가 악이라면서,

하도 쓰지 말라는 사람이 많아서 살짜쿵 고민을 했더랬다.


goto 문을 사용하면 100배는 더 편해지고, 명료해지는데 왜 쓰지 말라는건지;;;


goto 문은 이럴때 사용한다.


1. 예외 (에러) 처리

  1. int someFunction ( ... ) {
  2.     unsigned char* uniData = NULL;
  3.     FILE* fpR = NULL;
  4.   ... open file & allocate buffer ...
  5.     if ( fread(uniData, sizeof(char), rsize, fpR) < 0 ) {
  6.         printf("Error, cannot read file, %d\n", rsize);
  7.         goto EXIT;
  8.     }
  9.   ...  ...
  10. EXIT:
  11.      // Release resource & EXIT
  12.      SAFE_FREE(uniData);
  13.      if ( fpR != NULL ) fclose(fpR);
  14.      return 0;
  15. }

try .. catch ... finally 같이...

에러 때문에 함수를 나갈 경우에, 나가기 전 자원 해제를 위해서 쓰는 편이다.
( 예제에는 안썼지만 return 값을 -1로 설정하는 부분도 넣어야겠죠? )




2. 중복된 반복문을 한번에 벗어날때.

  1.   ...
  2. for ( i = 0; i < 100; i++ ) {
  3.     for ( j = 0; j < 100; j++ ) {
  4.         if ( buf[i][j] == '\n' )
  5.            goto EXIT_LOOP;
  6.     }
  7. }
  8. EXIT_LOOP:
  9.   ...


2개야 뭐 어떻게 한다고 쳐도, 10개쯤 중복된 반복문을 goto 없이 한번에 어떻게 벗어나죠? -_-

찾아보니 자바에도 저런 방식을 지원하더라고요,

  1. class BreakWithLabelDemo {
  2.     public static void main(String[] args) {
  3.         int[][] arrayOfInts = { { 32, 87, 3, 589 },
  4.                                 { 12, 1076, 2000, 8 },
  5.                                 { 622, 127, 77, 955 }
  6.                               };
  7.         int searchfor = 12;
  8.         int i;
  9.         int j = 0;
  10.         boolean foundIt = false;
  11.     search:
  12.         for (i = 0; i < arrayOfInts.length; i++) {
  13.             for (j = 0; j < arrayOfInts[i].length; j++) {
  14.                 if (arrayOfInts[i][j] == searchfor) {
  15.                     foundIt = true;
  16.                     break search;
  17.                 }
  18.             }
  19.         }
  20.         if (foundIt) {
  21.             System.out.println("Found " + searchfor +
  22.                                " at " + i + ", " + j);
  23.         } else {
  24.             System.out.println(searchfor
  25.                                + " not in the array");
  26.         }
  27.     }
  28. }

14번째 줄을 보면, 반복문을 시작할 때 반복문에 라벨을 지정해주고,

반복문 전체를 한번에 벗어나는 방법을 지원해주고 있습니다.
( continue도 라벨을 지정해주고 상위 반복문의 루프로 가는 방법을 지원해줌 )

출처: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/branch.html




물론 while 문으로 전체를 감싼 다음에 에러가 생기면 break를 걸어주는 방식으로 한다는 의견도 있지만,

저것도 에러 체크가 다른 반복문 안에 있으면 무용지물이지...

게다가 indent도 한단계 더 들어가야하잖아!!! goto 쓰는게 100배 나아!!!

...

난 이제는 goto 없이는 c programming이 힘들어지는....OTL
And

색상표

|
어디선가 주워온 색상표 -_-;

그래도 대략 쓸만하다~ 흐흐흐~

And
prev | 1 | next