'2010/12/13'에 해당되는 글 2건

  1. 2010.12.13 [LINUX] FIND AND REPLACE with SED
  2. 2010.12.13 [IOS] KEYBOARD 화면 이동
FIND AND REPLACE with SED



Let us start off simple:
Imagine you have a large file ( txt, php, html, anything ) and you want to replace all the words "ugly" with "beautiful" because you just met your old friend Sue again and she/he is coming over for a visit.


This is the command:

CODE
$ sed -i 's/ugly/beautiful/g' /home/bruno/old-friends/sue.txt


Well, that command speaks for itself "sed" edits "-i in place ( on the spot ) and replaces the word "ugly with "beautiful" in the file "/home/bruno/old-friends/sue.txt"


Now, here comes the real magic:
Imagine you have a whole lot of files in a directory ( all about Sue ) and you want the same command to do all those files in one go because she/he is standing right at the door . . 
Remember the find command ? We will combine the two:

CODE
$ find /home/bruno/old-friends -type f -exec sed -i 's/ugly/beautiful/g' {} \;


Sure in combination with the find command you can do all kind of nice tricks, even if you don't remember where the files are located !


Aditionally I did find a little script on the net for if you often have to find and replace multiple files at once:

CODE
#!/bin/bash
     for fl in *.php; do
     mv $fl $fl.old
     sed 's/FINDSTRING/REPLACESTRING/g' $fl.old > $fl
     rm -f $fl.old
     done

just replace the "*.php", "FINDSTRING" and "REPLACESTRING" make it executable and you are set.

I changed a www address in 183 .html files in one go with this little script . . . but note that you have to use "escape-signs" ( \ ) if there are slashes in the text you want to replace, so as an example: 's/www.search.yahoo.com\/images/www.google.com\/linux/g' to change www.search.yahoo.com/images to www.google.com/linux




For the lovers of perl I also found this one:

CODE
# perl -e "s/old_string/new_string/g;" -pi.save $(find DirectoryName -type f)

But it leaves "traces", e.g it backs up the old file with a .save extension . . . so is not really effective when Sue comes around ;-/


출처 : http://www.nicegass.co.kr/52

'개발 > Linux' 카테고리의 다른 글

[LINUX] Subversion설치  (0) 2011.02.07
[LINUX] CentOS 5.5에 CMake 설치  (0) 2010.12.20
[LINUX] NFS 설치 및 설정  (0) 2010.11.11
[LINUX] HDD 복사  (0) 2010.10.28
[LINUX] TIME SYNC  (0) 2010.10.28
Posted by 나랑살자
,
로그인 창을 구성할 경우에, 키보드가 나오면서 로그인 UITextField영역을 덮어 버리는 경우가 있다. 이 경우 화면설계를 할 때 하단에 키보드가 나왔을 때의 영역을 고려해서 로그인 텍스트 필드를 배치하는 경우도 있다.하지만, 임시방편일 뿐이고, 보다 근본적인 방법으로 키보드가 나올 때 해당 UIView를 위로 올렸다가 키보드가 사라질 때 그걸 내리는 방법으로 구현해야 한다.

이 방법을 좀 더 세부적으로 보면
1. UIKeyboard가 나타나는 이벤트를 감지했을 때
2. 키보드 아래쪽의 UIView영역을 키보드 높이 만큼 위로 이동시킨다.
3. 키보드 입력이 모두 끝나, 키보드 닫는 이벤트가 나왔을 때
4. 키보드를 사라지게 만드면서, UIView를 원래의 위치로 내린다.

구현을 위해서,

먼저 UIKeyboardWillShowNotification 이벤트가 발생할 때, keyboardWillShow 메소드를 호출하도록 등록한다.
- (void)loadView
{    
    [super loadView];    
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(keyboardWillShow:) 
                                                 name:UIKeyboardWillShowNotification 
                                               object:self.view.window];
}
keyboardWillShow 메소드는 다음과 같은 형태이다.

- (void)keyboardWillShow:(NSNotification *)notif
{
    // The keyboard will be shown. If the user is editing the author, adjust the display so that the
    // author field will not be covered by the keyboard.
    if ( [[self userIDTextField] isFirstResponder] && self.view.frame.origin.y >= 0)
    {
        [self setViewMovedUp:YES];
    }
    else if ( [[self userIDTextField] isFirstResponder] && self.view.frame.origin.y < 0)
    {
        [self setViewMovedUp:NO];
    }
}



해당 notification이 발생했을 때 위 메소드가 실행되고, 
키보드의 상태에 따라서 View를 올릴지 내릴지 애니메이션을 시켜주는 setViewMovedUp 메소드를 호출해준다.

- (void)setViewMovedUp:(BOOL)movedUp
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    // Make changes to the view's frame inside the animation block. They will be animated instead
    // of taking place immediately.
    CGRect rect = self.view.frame;
    if (movedUp)
    {
        // If moving up, not only decrease the origin but increase the height so the view 
        // covers the entire screen behind the keyboard.

        rect.origin.y -= kOFFSET_FOR_KEYBOARD;
        rect.size.height += kOFFSET_FOR_KEYBOARD;

    }
    else
    {
        // If moving down, not only increase the origin but decrease the height.
        rect.origin.y += kOFFSET_FOR_KEYBOARD;
        rect.size.height -= kOFFSET_FOR_KEYBOARD;
    }
    self.view.frame = rect;
    [UIView commitAnimations];
}



UIView의 애니메이션을 어떻게 시키는지 보여주는 메소드이다.


마지막으로 키보드 작업이 끝났을 때에 키보드를 내려주도록 textFieldDidEndEditing 메소드를 구현해주도록 하자.

- (void)textFieldDidEndEditing:(UITextField *)myTextField;
{
    if( self.view.frame.origin.y < 0 )
    {
        [self setViewMovedUp:NO];
    }
}


이제 키보드가 나타날 때 그 아래의 뷰도 함께 이동시킬 수 있게 되었다.

출처 :  http://alanduncan.net/old/index.php?q=node/13

'개발 > iOS' 카테고리의 다른 글

[iOS] XCode gloss effect 없애기  (0) 2012.03.24
[iOS] UITableView Cell 변경 animation  (0) 2011.04.29
[IOS] image size  (0) 2010.11.28
[XCODE] Breakpoint가 안먹을 때  (0) 2010.11.28
[XCODE] 메모리 관리 규칙  (0) 2010.11.16
Posted by 나랑살자
,