![]() |
|
|
|
|
|||||||
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| regexp help | TinCanFury | Shell Programming and Scripting | 0 | 04-06-2008 03:21 PM |
| In Help, Substitute Text ... | solidhelix08 | Shell Programming and Scripting | 6 | 02-07-2008 01:21 AM |
| regexp with sed again!!! | andy2000 | Shell Programming and Scripting | 2 | 05-03-2007 07:15 AM |
| Substitute in vi | kingdbag | UNIX for Dummies Questions & Answers | 5 | 01-17-2007 10:42 AM |
| regexp | penfold | UNIX for Advanced & Expert Users | 1 | 06-28-2005 04:45 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
vi + regexp + substitute
Another enigma (for me)
Using VI I edit some files in which I want to erase many lines I don't need anymore usually I do something like that: Code:
:%s/line_to_suppress//g but in this case, the pattern to erase contains some special characters so I do it like that: Code:
:%s#line_to_suppress_with_special_characters##g Code:
:%s/*line_to_suppress//g the best way would be to suppress each line containing my pattern, but I don't know how to do that I'm sure it's pretty easy for many among you, so if one have a bit of time, it would help me a lot Thanx |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
Code:
blabla 'toto' rep:/titi/toto/ if I understand what you mean, I should do like this: Code:
:%s/^.*blabla\ \'toto\'\ rep\:\/titi\/toto\/// |
|
||||
|
Quote:
Code:
:%s/^.*blabla 'toto' rep:\/titi\/toto\/// Cheers ZB |
|
|||
|
Quote:
but one more question it erase the lines, but it doesn't suppress them... any hint? |
|
|||
|
Quote:
xxxxxxxxxxx xxxxxxxxxxx blabla 'toto' rep:/titi/toto/ xxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx blabla 'toto' rep:/titi/toto /blabla 'toto' rep:/titi/toto/ xxxxxxxxxxx blabla 'toto' rep:/titi/toto/ blabla 'toto' rep:/titi/toto/ xxxxxxxxxxx File after: xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx Result I wish to have: xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx |
|
|||
|
Quote:
and is it possible without trouble that infile=outfile? |
|
||||
|
Yes, you can add metacharacters such as
sed "/^.*blabla\ 'toto'\ rep:\/titi\/toto\/.*$/d" infile > outfile Also; you can use the -i flag to sed if your version supports it to edit the file in-place, although I personally wouldn't recommend it - at least this way with redirection you keep your original intact incase you form your "sed" badly and ruin the file! Cheers ZB |
||||
| Google UNIX.COM |
| Thread Tools | |
| Display Modes | |
|
|
|
The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
|
| 421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash exec bash for loop close_wait command copy/move folder in unix couldn't set locale correctly curses.h cut command in unix dead.letter find grep find null character in a unix file grep multiple lines grep or grep recursive inaddr_any inappropriate ioctl for device ksh if logrotate.conf lynx javascript mailx attachment mget mtime ping port remove first character from string in k shell replace space by comma , perl script scp recursive segmentation fault(coredump) sftp script snoop unix stale nfs file handle syn_sent tar exclude test: argument expected unix unix .profile unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com vi substitute vi+substitute+end+of+line+character while loop within while loop shell script |