how to delete away text in a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to delete away text in a file?
# 1  
Old 01-06-2006
how to delete away text in a file?

I have this xml file which is call p.txt and it contains the follwing:
16:13:56 Msg send to Queue=[<pregate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<system_c>HPREGATE</system_c>
<trans_c>HSPG</trans_c>
<trans_dt>20060105161333</trans_dt>
<user_id_m></user_id_m>
<func_c>C</func_c>
<pm_n>XA 4650H</pm_n>
<chassis_type>20</chassis_type>
<chassis_ulw>00000</chassis_ulw>
<pager_n>90000000</pager_n>
<pager_mode>M</pager_mode>
<source_c>P</source_c>
<import>
<purp_i>D</purp_i>
<cntr_n>KKTU 7247736 </cntr_n>
<gway_to>T</gway_to>
<dvr_pass_n> </dvr_pass_n>
<hlr_creg_n>12267750000M</hlr_creg_n>
<nmt_n> </nmt_n>
<new_cntr_n> </new_cntr_n>
<new_nmt_n> </new_nmt_n>
<gate_n></gate_n>
<mpt_i> </mpt_i>
</import>
</pregate>
16:33:36 Sending Message :<pregate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<system_c>HPREGATE</system_c>
<trans_c>HSPG</trans_c>
<trans_dt>20060105163319</trans_dt>
<user_id_m></user_id_m>
<func_c>C</func_c>
<pm_n>XA 7359E</pm_n>
<chassis_type>20</chassis_type>
<chassis_ulw>00000</chassis_ulw>
<pager_n>94939929</pager_n>
<pager_mode>M</pager_mode>
<source_c>P</source_c>
<export>
<purp_i>S</purp_i>
<cntr_n>CRLU 5129584 </cntr_n>
<tt_i> </tt_i>
<new_cntr_n> </new_cntr_n>
<gway_to>T</gway_to>
<old_nmt_n> </old_nmt_n>
<kd_i>Y</kd_i>
<gate_n>5</gate_n>
<mpt_i>N</mpt_i>
<hlr_creg_n>12267750000M</hlr_creg_n>
<tt_frm_dt> </tt_frm_dt>
<tt_to_dt> </tt_to_dt>
</export>
</pregate>

as you can see the bold text are the one that i need to delete away and there are alot more xml set of data in the p.txt. so any ideas how to delete away the data??
# 2  
Old 01-06-2006
For a sed solution, this will work. I assumed that your timestamp would be of the pattern hh:mm:ss

Code:
sed -e 's_^..:..:.. .*<pregate_<pregate_g' sample.txt > sample.modified

Else this will work in any case

Code:
sed -e 's_^.\{,2\}:.\{,2\}:.\{,2\} .*<pregate_<pregate_g' sample.txt > sample.modified

# 3  
Old 01-06-2006
thanks Smilie however i need to put this in a script so i try to write this down:

`sed -e 's_^.\{,2\}:.\{,2\}:.\{,2\} .*<pregate_<pregate_g' p.txt > sample.modified`

however i get this msg :
sed: command garbled: s_^.\{,2\}:.\{,2\}:.\{,2\} .*<pregate_<pregate_g

sorry as im still new to scripting....
# 4  
Old 01-06-2006
Quote:
Originally Posted by forevercalz
`sed -e 's_^.\{,2\}:.\{,2\}:.\{,2\} .*<pregate_<pregate_g' p.txt > sample.modified`
If in a script, why the `backticks` ? Drop those.
# 5  
Old 01-08-2006
thanks vino for your help Smilie
# 6  
Old 01-08-2006
thanks vino Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Delete records based on a text file from a text file

Hi Folks, I am a novice and need to build a script in bash. I have 2 text files data.txt file is big file, column 2 is the we need to search and delete in the output. The filter file contains the rows to be deleted. Data.txt state city zone Alabama Huntsville 4 California SanDiego 3... (3 Replies)
Discussion started by: tech_frk
3 Replies

2. Shell Programming and Scripting

How to delete lines of a text file based on another text file?

I have 2 TXT files with with 8 columns in them(tab separated). First file has 2000 entries whereas 2nd file has 300 entries. The first file has ALL the lines of second file. Now I need to remove those 300 lines (which are in both files) from first file so that first file's line count become... (2 Replies)
Discussion started by: prvnrk
2 Replies

3. Shell Programming and Scripting

delete text from each record in a file

Hi guys, I have been given a small task to do and I am stuck already. I have to format a file with people's emails address in it ready for pasting into the BCC section of an email. The file looks like this:- bob@ibm.com SMTP BOB SMITH text text text sue@icl.org SMTP Susy Smith text text... (8 Replies)
Discussion started by: joe_evans
8 Replies

4. Shell Programming and Scripting

How to delete lines from text file?

hi guys, I have very large txt files (200GB) and just want to to delete the first two lines (headers). So far I used sed -i '1,2d' infile.txtbut this command always takes extremely long as it writes all again. Is there a better way to do it (ie just to delete the lines without writing all... (2 Replies)
Discussion started by: TuAd
2 Replies

5. UNIX for Dummies Questions & Answers

How to delete one line from a text file

PATTERN="" sed "/$PATTERN/d" $file In the file data is stored as ::: ::: I need to delete only the line containing the PATTERN pls help to point out why the above code is not working (4 Replies)
Discussion started by: thomsandy
4 Replies

6. Shell Programming and Scripting

Delete block of text in one file based on list in another file

Hi all I currently use the following in shell. #!/bin/sh while read LINE do perl -i -ne "$/ = ''; print if !m'Using archive: ${LINE}'ms;" "datafile" done < "listfile" NOTE the single quote delimiters in the expression. It's highly likely the 'LINE' may very well have characters in it... (3 Replies)
Discussion started by: Festus Hagen
3 Replies

7. UNIX for Dummies Questions & Answers

Delete line in text file

Hi, How do I go about deleting a line in a text file. I have used grep to find a particlular word, now how do I delete the line? so far I got: grep -i $keyword file.txt (6 Replies)
Discussion started by: Berserk
6 Replies

8. Shell Programming and Scripting

How to delete a particular text without opening the file.

Hi, Could someone tell me how to delete a particular text inside an existing file without opening the file? e.g. I have a text file called mytext.txt which contains three lines of text below and I want to delete “ ;” and delete the second line “b ;” including the carriage return. a ; b ; c ;... (12 Replies)
Discussion started by: stevefox
12 Replies

9. Shell Programming and Scripting

Delete first line from any text file ?

What command I can use to delete first line from any text file ? Thk (5 Replies)
Discussion started by: aungomarin
5 Replies

10. Shell Programming and Scripting

delete last line from text file

I have a file with which i must remove the last line of the file (the footer). I know how to copy and redirect with tail -1 etc, but how do i delete it permanentely (4 Replies)
Discussion started by: hcclnoodles
4 Replies
Login or Register to Ask a Question