Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to remove words in a textfile

Status
Not open for further replies.

zanzemaj

Programmer
Nov 2, 2006
35
NZ
I have a text file named tmp4.txt with sample records:
Code:
MISC_INT 05/30/2007 12:14:20 TABLE xx_httj  4,150 BYTES, 63 ROWS ARCHIVED FOR THIS
STORE_INT 05/30/2007 12:14:22 VIEW fret_xxfe  6,392,925 BYTES, 182,655 ROWS
STORE_INT 05/30/2007 12:14:25 TABLE bkup_x  4,756,990 BYTES, 135,914 ROWS
STORE_INT 05/30/2007 12:14:27 TABLE dsakj_djjsa  7,584 BYTES, 16 ROWS ARCHIVED
STORE_INT 05/30/2007 12:14:29 VIEW pll_xxx_excpalddc 49 BYTES, 1 ROWS ARCHIVED FOR
STORE_INT 05/30/2007 12:14:30 TABLE ldasd_sads_ssss_xxxx 0 BYTES, 0 ROWS ARCHIVED
I need the file tmp4.txt to look like this:
Code:
MISC_INT TABLE xx_httj  4,150  63 
STORE_INT VIEW fret_xxfe  6,392,925 182,655 
STORE_INT TABLE bkup_x  4,756,990  135,914 
STORE_INT TABLE dsakj_djjsa  7,584 16 
STORE_INT VIEW pll_xxx_excpalddc 49 1 
STORE_INT TABLE ldasd_sads_ssss_xxxx 0 0
Basically, how do i remove the second and third fields and the words after the numbers? That is remove the date, time, the word BYTES, and remove the word ROWS and after that.
To start with, here's my code that removes the word "BYTES,"
Code:
sed "s/"BYTES,"/ /g" tmp4.txt
Highly appreciate your suggestions. Thanks.
 
so, elaborating a bit on your sed code:

Code:
sed 's!../../.... ..:..:..!!; s!BYTES,!!; s!ROWS.*$!!' tmp4.txt

Notes:

any pattern delimiter can be chosen - I used ! because / is in the date pattern

no need for the g modifier in this case, because each pattern needs to modified/deleted just once)

you can specify multiple sed cammands if you separate them by semicolons.

HTH,

p5wizard
 
Thank you p5wizard, this works as expected. One more question, how do I remove multiple spaces? I need only one space between the fields. Thanks.
 
sed 's!../../.... ..:..:..!!;s!BYTES,!!;s!ROWS.*$!![!];s! *! !g[/!]' tmp4.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you p5wizard and PHV for your replies. Everything works!

[2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top