Deleting a pattern in UNIX without deleting the entire line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting a pattern in UNIX without deleting the entire line
# 15  
Old 03-15-2013
You could try these:

This should delete all the patterns starting with '[5]' until the next pattern:
Code:
sed 's/\[5\][^;][^;]*;//g' file

This should delete all the patterns starting with '[5]' and everything after it until the end of the line:
Code:
sed 's/\[5\].*//g' file

This User Gave Thanks to Scrutinizer For This Post:
# 16  
Old 03-15-2013
Thank you very much indeed. I used
Code:
sed -i -e 's/\[5\].*//g' file

thanks a lot

Last edited by Scrutinizer; 03-15-2013 at 04:54 AM.. Reason: quote tags -> code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting lines on matching certain pattern

hi I have a large xml file from which i have taken few lines . In this file I have to find for the string </invoices> and check if the 3 rd line after this string does not begin with <portCode> ,then i have to delete the string </invoices> and the next line having the string </shippingBill>... (13 Replies)
Discussion started by: sunnyboy
13 Replies

2. Shell Programming and Scripting

Help with a deleting lines based on a pattern

I have a header-detail file that goes like this: SHP00288820131021110921 ORDER0156605920131021110921INMMMMFN DETAIL0004 4C2Z 10769 AAFC 0000009600000094 4C2Z 10769 AAFC 0000672107 OIL DETAIL0002 ER3Z 14300 E 0000001300000012 ER3Z 14300 E 0000672107 OIL... (3 Replies)
Discussion started by: rbaggio666
3 Replies

3. Shell Programming and Scripting

retaining only the second line with a pattern and deleting all others

Hi, I have a file: 5 T1AxialPremosaic ok 512 448 23 1 284000-000005-000001.dcm 6 T2_SPACE ok 256 256 176 1 465000-000006-000001.dcm 7 FLAIRmosaic ok 512 432 23 1 748000-000007-000001.dcm 8 T2_SPACE ok 256 256 1 171000-000008-000001.dcm 9 T2_SPACE ok 256 256 1 218000-000009-000001.dcm... (5 Replies)
Discussion started by: goodbenito
5 Replies

4. Shell Programming and Scripting

Deleting pattern without removing line

I am trying to delete a pattern without removing line. I searched a lot in this forum and using those I could come up with sed command but it seems that command does not work. Here's how my file looks like: 1 ./63990 7 1171 ./63990 2 2425 ./63990 9 2539 ./63990 1 3125 ./63990 1 10141... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

5. Shell Programming and Scripting

sed: deleting 5 lines after a specified pattern

As an example (just an example, this could apply to any block of text) say I have this: architecture x86_64 cputype CPU_TYPE_X86_64 cpusubtype CPU_SUBTYPE_X86_64_ALL offset 4096 size 2972420 align 2^12 (4096) architecture ppc64 cputype CPU_TYPE_POWERPC64 cpusubtype... (3 Replies)
Discussion started by: pcwiz
3 Replies

6. Shell Programming and Scripting

Searching a pattern in file and deleting th ewhole line containing the pattern

Hi All, Please can someone assist in the script I have made that searches a pattern in a file and delete the whole line containing the pattern. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read value # check if the user has... (1 Reply)
Discussion started by: Shazin
1 Replies

7. Shell Programming and Scripting

deleting a pattern from a file

say i have a file with the following contents 0x20 0x20 0xc23886 > 0xc12354 > 0xc567555555 i want to delete "> " pattern and keep the rest of the file (6 Replies)
Discussion started by: lassimanji
6 Replies

8. Shell Programming and Scripting

deleting lines after pattern using sed

I have seen there are many sed posts but still it is quite difficult to apply other post to my own problem How can I delete all lines in a file from 2 lines after this pattern *End_fine_coreg:_NORMAL to the end of file? Cheers (2 Replies)
Discussion started by: larne
2 Replies

9. Shell Programming and Scripting

prom in deleting a pattern

hi guys, i have a directory.inside that so many directories and files are there.i want to search the complete directory for a pattern in all the .txt files.if i will find that pattern then i want to delete that pattern from that file. please help me out. i want it urgent (18 Replies)
Discussion started by: suvendu4urs
18 Replies

10. UNIX for Advanced & Expert Users

Deleting UNIX End of Line Chachracter \000

Hi, I have this file which has some octal NULL characters (\000). I need to replace these characters with an ASCII NULL. I've tried using Perl, the UNIX tr command.. History of this I received a COBOL generated file, ran the od command to convert to a xxx byte per record file. Now,... (3 Replies)
Discussion started by: uchachra
3 Replies
Login or Register to Ask a Question