prom in deleting a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting prom in deleting a pattern
# 8  
Old 04-10-2008
if u are not using any shell variable inside the sed syntex.. thn use single quotes instead of double with in the sed. hope it 'll work

sed 's/^M//g' $file
# 9  
Old 04-10-2008
for file in `find . -name "*.txt" -print`
do
sed "s/suvendu/anil /g" $file > temp; mv temp $file;
done
~


when i am replacing suvendu with anil it is working
but when i want replace it from ^M to ' ' it is not working
so i dcontknow whats the problem in this
# 10  
Old 04-10-2008
Quote:
Originally Posted by anchal_khare
if u are not using any shell variable inside the sed syntex.. thn use single quotes instead of double with in the sed. hope it 'll work

sed 's/^M//g' $file
for file in `find . -name "*.txt" -print`
do
sed 's/^M// g' $file > temp; mv temp $file;
done
~
i have done like this
but again it is not working yarr
# 11  
Old 04-10-2008
post the error msg...
also post any sample file
# 12  
Old 04-10-2008
Quote:
Originally Posted by anchal_khare
post the error msg...
also post any sample file
no eroor message is theer
it is executing successfully
but no change in the file ok

..................CPR AIRBUS NEW TECHNO ^M 000809786
..................CPR AIRBUS NEW TECHNO ^M 000809787
..................CPR AIRBUS NEW TECHNO ^M 000809788
..................CPR AIRBUS NEW TECHNO ^M 000809789
..................CPR AIRBUS NEW TECHNO ^M 000809790
like this it is there
in all the .txt files
but when i am executing the script no error is there
but after that no change in the file also
ok
so just check out this thing
# 13  
Old 04-10-2008
try this

for file in `find . -name "*.txt" -print`
do
sed 's/\^M// g' $file > temp; mv temp $file;
done

it 'll work

Last edited by clx; 04-10-2008 at 05:19 AM..
# 14  
Old 04-10-2008
It's not clear whether the files and/or your command lines contain the two characters "^" and "M" or real actual carriage returns (ASCII 13). My uninformed guess is you are mixing these up.

It's also possible that your sed cannot cope with literal carriage returns. Try tr again in that case. If you cannot get tr to accept either '\015' (that's octal for 13) or a literal ctrl-M, you will need some heavier workaround.

Actually here's one.

Code:
find . -name '*.txt' -print | xargs -n 1 perl -i -pe 'y/\015/ /'

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

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

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

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

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

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

9. Shell Programming and Scripting

Delete lines between two patterns without deleting the second pattern

I want to delete lines like this sed '/FROM_HERE/,/TO_HERE/d' but I would like to *not* delete the second match, i.e. the TO_HERE line. How can I achieve this? Thank you! (1 Reply)
Discussion started by: Ilja
1 Replies

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