extract part of text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract part of text file
# 8  
Old 06-11-2010
Something like this?
Code:
awk '/^Content-Type.+plain/{f=1;getline}/^--/{f=0}/^(Subject|From)/||f{print}' infile

This User Gave Thanks to ripat For This Post:
# 9  
Old 06-11-2010
I find another post with more information!

Smilie

thanks to everyone

---------- Post updated at 10:41 AM ---------- Previous update was at 07:53 AM ----------

for my sourprise I discover that hotmail, takes other format.

Code:
From x@hotmail.com  Fri Jun 11 17:09:14 2010
Return-Path: <x@hotmail.com>
X-Original-To: x@localhost
Delivered-To: x@localhost
Received: from ubuntu (localhost [127.0.0.1])
    by ubuntu (Postfix) with ESMTP id BEB892696C
    for <x@localhost>; Fri, 11 Jun 2010 17:09:14 +0200 (CEST)
Delivered-To: x@gmail.com
Received: from gmail-pop.l.google.com [209.85.229.109]
    by ubuntu with POP3 (fetchmail-6.3.9-rc2)
    for <x@localhost> (single-drop); Fri, 11 Jun 2010 17:09:14 +0200 (CEST)
Message-ID: <BAY133-W394AF85AA21804B1A7DEDA6D90@phx.gbl>
Content-Type: multipart/alternative;
    boundary="_cc7e7bd6-5175-4c48-804d-8a25692af1e8_"
X-Originating-IP: [xxxx]
From: xx <xxx@hotmail.com>
To: <xxx@gmail.com>
Subject: TEST
Date: Fri, 11 Jun 2010 15:02:23 +0000
Importance: Normal
MIME-Version: 1.0
X-OriginalArrivalTime: 11 Jun 2010 15:02:24.0582 (UTC) FILETIME=[199F4E60:01CB0977]

--_cc7e7bd6-5175-4c48-804d-8a25692af1e8_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Here comes the message
_________________________________________________________________
=BFUn navegador seguro buscando est=E1s? =A1Protegete ya en www.ayudartepod=
ria.com!
www.ayudartepodria.com=

--_cc7e7bd6-5175-4c48-804d-8a25692af1e8_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px=3B
padding:0px
}
body.hmmessage
{
font-size: 10pt=3B
font-family:Verdana
}
--></style>
</head>
<body class=3D'hmmessage'>
nene                           <br /><hr />=BFUn navegador seguro buscando est=E1s? <a hre=
f=3D'www.ayudartepodria.com' target=3D'_new'>=A1Protegete ya en www.ayudart=
epodria.com!</a></body>
</html>=

--_cc7e7bd6-5175-4c48-804d-8a25692af1e8_--

the problems are. How take the information in the new format.
How can I determine wich awk have to execute ?

Code:
From: xx <xxx@hotmail.com>
Subject: TEST
Here comes the message

thanks

Last edited by waxo; 06-11-2010 at 10:34 AM..
# 10  
Old 06-11-2010
Try this:
Code:
 awk '/^Content-Type.+plain/{f=1;while($0!="")getline}/^--/||/^__/{f=0}/^(Subject:|From:)/||f{print}'  infile


Last edited by ripat; 06-11-2010 at 01:24 PM.. Reason: fixes deletion of unwanted lines
# 11  
Old 06-22-2010
Quote:
Originally Posted by ripat
Something like this?
Code:
awk '/^Content-Type.+plain/{f=1;getline}/^--/{f=0}/^(Subject|From)/||f{print}' infile

Can someone explain me what exactly does this code ?

thanks

I think that, first searches the text between "Content-Type.+plain" and "--" prints it.
then searches de lines with the text Subject|From and puts in the top. (f=0) print in line 0 ??

is it ?

Last edited by waxo; 06-22-2010 at 04:04 PM..
# 12  
Old 06-22-2010
Code:
'/^Content-Type.+plain/{f=1;getline}

when line matched by "^Content-Type.+plain" is found, then next line is put in $0 by getline, and "f" is set to 1.
Code:
/^--/{f=0}

When line is matched by "^--", then "f" is set back to 0. So Those two commands set "f" variable to 1 for all lines between "^Content-Type.+plain" and "^--" in file. Next command:
Code:
/^(Subject|From)/||f{print}

checks if line contain "Subject" of "From" as first word, or that "f" variable is true (other than 0). If that is the case, then line is printed. So last command prints lines that were matched by "^(Subject|From)" or those between "^Content-Type.+plain" and "^--", becouse "f" variable was set to 1 for them.
This User Gave Thanks to bartus11 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substr/Instr in shell script or extract part of text

Hi, I need to extract part of a text to two variables text is "PL/SQL procedure successfully completed. ERROR ----------------------------------------------------------------- Test Error Message PLUSVAR ---------- 1" I want "Test Error Message" in one variable and "1" in another variable.... (11 Replies)
Discussion started by: vedavrath
11 Replies

2. Shell Programming and Scripting

Extract a part of variable/line content in a file

I have a variable and assigned the following values ***XYZ_201519_20150929140642_20150929140644_211_0_0_211 I need to read this variable from backward and stop read when I get first underscore (_) In this scenario I should get 211 Thanks Kris (3 Replies)
Discussion started by: mkris
3 Replies

3. Programming

Extract part of an archive to a different file

I need to save part of a file to a different one, start and end offset bytes are provided by two counters in long format. If the difference is big, how should I do it to prevent buffer overflow in java? (7 Replies)
Discussion started by: Tribe
7 Replies

4. Shell Programming and Scripting

Extract the part of sequences from a file

I have a text file, input.fasta contains some protein sequences. input.fasta is shown below. >P02649 MKVLWAALLVTFLAGCQAKVEQAVETEPEPELRQQTEWQSGQRWELALGRFWDYLRWVQT LSEQVQEELLSSQVTQELRALMDETMKELKAYKSELEEQLTPVAEETRARLSKELQAAQA RLGADMEDVCGRLVQYRGEVQAMLGQSTEELRVRLASHLRKLRKRLLRDADDLQKRLAVY... (8 Replies)
Discussion started by: rahim42
8 Replies

5. Shell Programming and Scripting

Extract part of file

Hello All, I need to extract part of a file into a new file My file is Define schema xxxxxx Insert into table ( a ,b ,c ,d ) values ( 1, 2, 3, (15 Replies)
Discussion started by: nnani
15 Replies

6. Shell Programming and Scripting

extracting part of a text file

Hi guys So I have a very large log file where each event is logged along with the time that it occurred. So for e.g. The contents of the file look like: ... 12:00:07 event 0 happened. 12:01:01 event 1 happened. 12:01:05 event 2 happened. 12:01:30 event 3 happened. 12:02:01 event 4... (10 Replies)
Discussion started by: alinaqvi90
10 Replies

7. Programming

c program to extract text between two delimiters from some text file

needa c program to extract text between two delimiters from some text file. and then storing them in to diffrent variables ? text file like 0: abc.txt ========= aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass... (7 Replies)
Discussion started by: kukretiabhi13
7 Replies

8. Shell Programming and Scripting

How to extract certain part of log file?

Hi there, I'm having some problem with UNIX scripting (ksh), perhaps somebody can help me out? For example: ------------ Sample content of my log file (text file): -------------------------------------- File1: .... info_1 ... info_2 ... info_3 ... File2: .... info_1 ... info_2 ...... (10 Replies)
Discussion started by: superHonda123
10 Replies

9. UNIX for Dummies Questions & Answers

Extract a part of file name

Hi, I want to extract a part of filename and pass it as a parameter to one of the scripts. Could someone help. File name:- NLL_NAM_XXXXX.XXXXXXX_1_1.txt. Here i have to extract only XXXXX.XXXXXXX and the position will be constant. that means that i have to extract some n characters from... (6 Replies)
Discussion started by: dnat
6 Replies

10. Shell Programming and Scripting

Moving part of Text in a file

Hi, I have this text in a file where I need to move part of the text.... <Relation1 OriginatingObjectID="Holding_1" RelatedObjectID="Party_1" id="Relation_1"> <OriginatingObjectType tc="4">Holding</OriginatingObjectType> <RelatedObjectType tc="6">Party</RelatedObjectType>... (4 Replies)
Discussion started by: mgirinath
4 Replies
Login or Register to Ask a Question