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
can anyone help with shell script command about searching word with grep command? aintour Shell Programming and Scripting 2 10-14-2009 04:51 PM
Need to Write Shell Script based off of this shell command Rally_Point Shell Programming and Scripting 3 06-10-2009 05:19 PM
Help with ssh command in shell script vikash_k Shell Programming and Scripting 6 05-21-2009 11:20 AM
Sed command in shell script Todd88 Shell Programming and Scripting 1 07-05-2008 01:15 PM
how to use cd command in shell script LAKSHMI NARAYAN Shell Programming and Scripting 3 09-09-2007 06:04 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 1 Week Ago
murphybr murphybr is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 2
shell script/sed command help

First off I have read the man pages for sed and am still having trouble working on a script to remove portions of a log:

My goal is to take a log file to be emailed, read the file and strip the portions away AFTER the line MIME-Version:1.0
and strip away until it to the line starting with Content-Type:application.

(HOWEVER, i would like for the sed command to keep the boundry line written before the Content-Type:application line.)

ex. removing everything bold and italicized. note this will be static so it wont always be the same information or linecount.

Code:
MIME-Version: 1.0

--_002_67C1678059C61F408194E53907AFB5CC09FB7E8BE6ISEXMB01RPadr_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable


Here goes nothing.
-----Original Message-----
From: =20
Sent: Friday, November 13, 2009 2:42 PM
To: 
Subject: send to myself

This will be forwarded to mail2fax.

--_002_67C1678059C61F408194E53907AFB5CC09FB7E8BE6ISEXMB01RPadr_
Content-Type: application/pdf;

Any help would be appreciated. thank you.

Last edited by radoulov; 1 Week Ago at 06:09 PM.. Reason: added code tags
  #2 (permalink)  
Old 1 Week Ago
steadyonabix steadyonabix is offline
Registered User
  
 

Join Date: Oct 2009
Location: UK
Posts: 154
Try this: -

Code:
nawk '
        /MIME-Version: 1.0/{ print;s++ }
        /Content-Type: application\/pdf/{
                print l
                print
                s = 0
        }
        { l = $0 }
        (s){ next }
' infile


---------- Post updated at 10:21 PM ---------- Previous update was at 10:16 PM ----------

Or

Code:
nawk '
        /MIME-Version: 1.0/{ print;s++ }
        /Content-Type: application\/pdf/{
                print l
                s = 0
        }
        { l = $0 }
        (s){ next }
        { print }
' infile
  #3 (permalink)  
Old 1 Week Ago
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
If AWK is acceptable:

Code:
awk '!f; /^MIME-Version/ { f = 1 }
/^Content-Type: application/ { print p RS $0; f-- }
{ p = $0 }' infile
Do not use /usr/bin/awk on Solaris.
  #4 (permalink)  
Old 4 Days Ago
murphybr murphybr is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 2
does it change anything if I would need to have the command in a script that needs to call a file to read such as it would call a file "Random.txt" and read the information then strip it out?
  #5 (permalink)  
Old 4 Days Ago
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
No, it shouldn't change anything.
Sponsored Links
Reply

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 02:39 AM.


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