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!

Removing words in a file.

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
Can somebody help me? New to unix and trying to remove certain letters in a file. Can a script do this? For example, a logfile has the first three letters of each month as part of a time stamp. I would like a script to remove the first three letters of every month, ie.. Jan, Feb, Mar, Apr, etc.

How can I do this? Grep? Awk? Sort?

Thank you.

Chris
 
a sample file, pls!

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Here is a sample and thank you.


Dec 30 15:44:27 localhooo sendmail[3213473]: hBUKiPf33213473: to=MICH.ACCT-ASA.8
98U04@COMPANY.COM, ctladdr=MGR.OONNN (142/121), delay=00:00:02, xdelay=00:0
0:02, mailer=relay, pri=30128, relay=localhooo [111.11.111.1], dsn=2.0.0, ooat=Sent
(hBUKiQAQ1901345 Message accepted for delivery)
Dec 30 15:44:27 localhooo sendmail[3409186]: hBUKiQAQ1901345: to=<MICH.ACCT-ASA.
898U04@COMPANY.COM>, ctladdr=<MGR.OONNN@xxx0500.company.com> (142/121),
delay=00:00:01, xdelay=00:00:00, mailer=esmtp, pri=120923, relay=ms00net2.opr.oo
ateooo.org. [11.11.11.86], dsn=2.0.0, ooat=Sent (OAA25528 Message accepted for
delivery)
Dec 30 16:07:05 localhooo sendmail[2033007]: hBUL756x2033007: from=MGR.OONNN,
size=885, class=0, nrcpts=1, msgid=<200312302107.hBUL756x2033007@xxx0500.ooate
ooo.com>, relay=MGR.OONNN@localhooo
Dec 30 16:07:06 localhooo sendmail[3541224]: hBUL76AQ3541224: from=<MGR.OONNN
@xxx0500.company.com>, size=885, class=0, nrcpts=1, msgid=<200312302107.hBUL7
56x2033007@xxx0500.company.com>, proto=ESMTP, daemon=MTA, relay=localhooo [12
7.0.0.1]
Dec 30 16:07:07 localhooo sendmail[2033007]: hBUL756x2033007: to=ROB.OOOOO.BBZ
0@COMPANY.COM, ctladdr=MGR.OONNN (142/121), delay=00:00:02, xdelay=00:00:02
, mailer=relay, pri=30114, relay=localhooo [111.11.111.1], dsn=2.0.0, ooat=Sent (hB
UL76AQ3541224 Message accepted for delivery)
Dec 30 16:07:07 localhooo sendmail[3735627]: hBUL76AQ3541224: to=<ROB.OOOOO.BB
Z0@COMPANY.COM>, ctladdr=<MGR.OONNN@xxx0500.company.com> (142/121), dela
y=00:00:01, xdelay=00:00:00, mailer=esmtp, pri=121267, relay=ms00net2.opr.ooatef
vvv.org. [11.11.11.86], dsn=2.0.0, ooat=Sent (PAA00866 Message accepted for del
ivery)
 
depending on how well-behaved your data is:

sed -e 's/^...//g' myFile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
An awk way:
Code:
awk '
/^(Jan|Feb|...|Nov|Dec) /{
 print substr($0,5);next
}
{print}
' /path/to/inputfile >outputfile

Hope This Help
PH.
 
Tigerina,
I have two questions to clarify what you're trying to do:
1. Do all of your lines start with a three letter month name? It is not obvious because of the formatting after the post.
2. Do you really want to remove three characters, thus leaving a blank space at the beginning of the new lines, or do you want to remove that space as well?
Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top