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
# 8  
Old 02-16-2013
Code:
awk '{print $1"\tAT50"}' file


Last edited by radoulov; 02-18-2013 at 01:21 PM.. Reason: Code tags.
This User Gave Thanks to indianya For This Post:
# 9  
Old 02-16-2013
Thank you
# 10  
Old 02-18-2013
Keep everything before the first space, then add on a TAB and a string:
Code:
sed 's/^\([^ ]*\) .*/\1<TAB-see note below>AT50/' filename

Note: replace "<TAB-see note below>" with a Tab character. To insert a TAB character in front of the "AT50" on the command line one would type Ctrl-V, followed by pressing the Tab key.
# 11  
Old 02-18-2013
Search for lines beginning with optional-spaces V not-spaces space length= whatever and replace the length = whatever with 'tab AT50', and print just these lines:
Code:
sed -n 's/^\( *V[^ ]*\) length=.*/\1 tab AT50/p'

# 12  
Old 03-15-2013
How can I delete this pattern '[5]* 'from 600 .tsv files ?

I tried
Code:
sed 's/[5]*//g'

but the changes are displayed rather than saved in the files themselves, can I channel the output somehow keeping the files names ?

Thanks a lot

---------- Post updated at 10:42 PM ---------- Previous update was at 10:32 PM ----------

The pattern is actually
"[5]species_name"

where species name is different in each of the 600 files, that's why I typed [5]*
# 13  
Old 03-15-2013
This particular command will delete the digit "5" everywhere in the file. Are you sure this is what you are looking for? GNU and BSD sed have a -i[SUFFIX] option that allows you to in-place edit multiple files and create a backup copy of the original in one go, but it is powerful, so try it in a test situation first until you are absolutely certain it does what you want it to do.

--edit--
[5]species_name is equivalent to 5species_name. [5]* means zero or more 5's.

What is you input and desired output, could you give examples?

Last edited by Scrutinizer; 03-15-2013 at 12:47 AM..
# 14  
Old 03-15-2013
yes, this is what happened when I used this particular command, and no, this is not what I want

I want to delete the pattern starting with [5] and ending with whatever

---------- Post updated at 10:49 PM ---------- Previous update was at 10:43 PM ----------

This is input file
Quote:
[0]Bacteria;[1]Cyanobacteria;[3]Prochlorales;[4]Prochlorococcaceae;[5]Prochlorococcus;[6]Prochlorococcus_marinus;
[0]Bacteria;[1]Cyanobacteria;[3]Prochlorales;[4]Prochlorococcaceae;[5]Prochlorococcus;[6]Prochlorococcus_marinus;
[0]Bacteria;[1]Cyanobacteria;[3]Prochlorales;[4]Prochlorococcaceae;[5]Prochlorococcus;
I want it to be
Quote:
[0]Bacteria;[1]Cyanobacteria;[3]Prochlorales;[4]Prochlorococcaceae;
[0]Bacteria;[1]Cyanobacteria;[3]Prochlorales;[4]Prochlorococcaceae;
[0]Bacteria;[1]Cyanobacteria;[3]Prochlorales;[4]Prochlorococcaceae;
 
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