The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete line in text file Berserk UNIX for Dummies Questions & Answers 6 12-16-2008 03:44 PM
How to delete a particular text without opening the file. stevefox Shell Programming and Scripting 12 02-21-2008 01:24 PM
Overwrite & Delete in Text File 33junaid Shell Programming and Scripting 11 08-16-2007 05:28 AM
Delete first line from any text file ? aungomarin Shell Programming and Scripting 5 05-16-2006 09:42 PM
delete last line from text file hcclnoodles Shell Programming and Scripting 4 06-25-2002 09:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-06-2006
forevercalz forevercalz is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 74
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 (permalink)  
Old 01-06-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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 (permalink)  
Old 01-06-2006
forevercalz forevercalz is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 74
thanks 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 (permalink)  
Old 01-06-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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 (permalink)  
Old 01-08-2006
forevercalz forevercalz is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 74
thanks vino for your help
  #6 (permalink)  
Old 01-08-2006
forevercalz forevercalz is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 74
thanks vino
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0