deleting a pattern from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting deleting a pattern from a file
# 1  
Old 04-30-2009
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
# 2  
Old 04-30-2009
You can use sed to trim the unwanted characters.

Code:
sed -i 's/^> //' file
# -i overwrite file with new content
# s/^> //'  substitute begin of line "^", greaterthan ">", {space} with nothing.

# 3  
Old 04-30-2009
Code:
printf '1,$s/^>//\n.\nwq' |ex - myFile

# 4  
Old 04-30-2009
thanks
# 5  
Old 04-30-2009
Quote:
Originally Posted by ldapswandog
You can use sed to trim the unwanted characters.

Code:
sed -i 's/^> //' file
# -i overwrite file with new content
# s/^> //'  substitute begin of line "^", greaterthan ">", {space} with nothing.

This is GNU-ism (not that there's anything wrong with that....[(c)Seinfeld])
# 6  
Old 04-30-2009
0xc0a80101
0xc0a80108
0xc0a80129
0x20
0xc0a80201
0xc0a80201
0xc0a80201
0xc0a80201
0xc0a80202
0xc0a80201
0xc0a80202
0xc0a80201
0x20

I want to sort this file.
The command that i am using is sort -u diff1.txt | tee diff1.txt
but diff1.txt is always empty.
what am I doing wrong
# 7  
Old 04-30-2009
Quote:
Originally Posted by lassimanji
0xc0a80101
0xc0a80108
0xc0a80129
0x20
0xc0a80201
0xc0a80201
0xc0a80201
0xc0a80201
0xc0a80202
0xc0a80201
0xc0a80202
0xc0a80201
0x20

I want to sort this file.
The command that i am using is sort -u diff1.txt | tee diff1.txt
but diff1.txt is always empty.
what am I doing wrong
you cannot 'tee' to the same file you're sort-ing.
Code:
sort -u diff1.txt | tee diff1_sorted.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

Deleting a pattern in UNIX without deleting the entire line

Hi I have a file: r58778.3|SOURCES={KEY=f665931a...,fw,221-705}|ERRORS={16_1:T,30_1:T,56_1:C,57_1:T,59_1:A,101_1:A,115:-,158_1:C,186_1:A,204:-,271_1:T,305:-,350_1:C,368_1:G,442_1:C,472_1:G,477_1:A}|SOURCE_1="Contig_1092402550638"(f665931a359e36cea0976db191ff60ff09cc816e) I want to retain... (15 Replies)
Discussion started by: Alyaa
15 Replies

3. Shell Programming and Scripting

awk - writing matching pattern to a new file and deleting it from the current file

Hello , I have comma delimited file with over 20 fileds that i need to do some validations on. I have to check if certain fields are null and then write the line containing the null field into a new file and then delete the line from the current file. Can someone tell me how i could go... (2 Replies)
Discussion started by: goddevil
2 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

deleting lines in a file that match a pattern without opening it

In Unix, how do I delete lines in a file that match a particular pattern without opening it. File contents are foo line1 misc whatever foo line 2 i want to delete all lines that have the pattern "foo" without opening the file. File should eventually contain misc whatever (1 Reply)
Discussion started by: osbourneric
1 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 multiple accourances of a pattern from a file

I have a .sh file with the following contents: a b c a a b d c i want to delete the multiple occurances and keep one. say there are 3 a's in the file. I want to delete 2 of them and just keep 1 occurance. (11 Replies)
Discussion started by: lassimanji
11 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. UNIX for Dummies Questions & Answers

Checking for a file in file pattern before deleting it

Hi, I need a script where I have delete all the files of type abc*.* from the directory /lmn/opq (passed as parameter to script) But I need to check if there is file of type abc*.* existing in the directory or not before I use the rm abc*.* command. Thanks (1 Reply)
Discussion started by: dsrookie
1 Replies

10. 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
Login or Register to Ask a Question