prom in deleting a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting prom in deleting a pattern
# 1  
Old 04-10-2008
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
# 2  
Old 04-10-2008
for file in `find $path -name "*.txt" -print`
do
sed "s/$pattern//g" $file > temp; mv temp $file;
done
# 3  
Old 04-10-2008
Quote:
Originally Posted by anchal_khare
for file in `find $path -name "*.txt" -print`
do
sed "s/$pattern//g" $file > temp; mv temp $file;
done
hai anchal
when i am executing this shell script it is saying that
mv: target `./*.txt' is not a directory
what is the problem
i am not getting
actually in my file i have to replace ^M with spaces.
sp what change i have to make over here
plz replay me ASAP
THANK U
# 4  
Old 04-10-2008
That error message doesn't make sense. What does find $path -name "*.txt" -print | less print for you (and did you remember to set path to something useful)?

The replacement is probably better done with tr -- if yours doesn't understand '\015' then try typing a real control-M there (might need to type ctrl-V ctrl-M to actually get one).

Code:
find $path -name "*.txt" -print" |
while read file; do
  tr '\015' ' ' <"$file" >"$file".tmp && mv "$file".tmp "$file"
done

# 5  
Old 04-10-2008
Quote:
Originally Posted by era
That error message doesn't make sense. What does find $path -name "*.txt" -print | less print for you (and did you remember to set path to something useful)?

The replacement is probably better done with tr -- if yours doesn't understand '\015' then try typing a real control-M there (might need to type ctrl-V ctrl-M to actually get one).

Code:
find $path -name "*.txt" -print" |
while read file; do
  tr '\015' ' ' <"$file" >"$file".tmp && mv "$file".tmp "$file"
done

hai
i have done like this
find $suvendu -name "*.txt" -print" |
while read file; do
tr '^M' ' ' <"$file" >"$file".tmp && mv "$file".tmp "$file"
done

but here again some problem is coming
like-
shell1.sh: line 3: unexpected EOF while looking for matching `"'
shell1.sh: line 5: syntax error: unexpected end of file
so whats the problem can u tell me
plz tell me ASAP
# 6  
Old 04-10-2008
remove incomplete " after -print.
# 7  
Old 04-10-2008
Quote:
Originally Posted by anchal_khare
remove incomplete " after -print.
but it is not working yarr
i dont know why
i have done like this
for file in `find . -name "*.txt" -print`
do
sed "s/^M//g" $file > temp; mv temp $file;
done
~

it is executing succesfully
but it is not changing anything
inside the .txt file
so plz give me the solution ASAP
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