split string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting split string
# 1  
Old 06-19-2012
split string

I am trying to get some data from a file and print it on the same line.
I have a script that gets the body of emails and display it, but i want it to display each emails body in one line no matter how big it is. eg

insted of this

Code:
email1: bla bla bla
bla bla bla
bal
email2: bla bla bla bal
bla bla bal

i want it to print

Code:
email1: bla bla bal bal bal bal
email2: bla bal bla blalba bla bla

the code i used to print the body is
Code:
awk '/Content-Type/{p=1;c++;print "Email-",c;}/Date/{p=0}p' file

Thank You!

Last edited by Scrutinizer; 06-19-2012 at 07:23 AM.. Reason: code tags also for data
# 2  
Old 06-19-2012
what is your full input ?
# 3  
Old 06-19-2012
Just changing your awk program a bit:

Code:
awk '/Content-Type/{p=1;c++;printf("\n%s%s ","Email-",c);}/Date/{p=0}p{printf("%s ",$0)} END{print}' file

# 4  
Old 06-19-2012
Quote:
Originally Posted by ygemici
what is your full input ?
Do you mean the actual body?

---------- Post updated at 09:00 PM ---------- Previous update was at 08:51 PM ----------

Quote:
Originally Posted by elixir_sinari
Just changing your awk program a bit:

Code:
awk '/Content-Type/{p=1;c++;printf("\n%s%s ","Email-",c);}/Date/{p=0}p{printf("%s ",$0)} END{print}' file

It is not printing the emails one after another line by line? it is still breaking the long emails.

thanks
# 5  
Old 06-19-2012
Quote:
Originally Posted by maddog21
It is not printing the emails one after another line by line? it is still breaking the long emails.
thanks
Sigh....Smilie why didn't I ask for the input before?

Please provide the input..
# 6  
Old 06-19-2012
Quote:
Originally Posted by elixir_sinari
Sigh....Smilie why didn't I ask for the input before?

Please provide the input..

X-Gm-Message-State: ALoCoQlKshFP6tmOEy2s1QR3S1Jz+MxBV14nq785bMuizQkLNlHBS5IO/6HVa+UBngxbf8sUkiU7

Hello chatura,

Applications Open Submit your Social Enterprise Project Idea - SEEDS Investment Fund; Free Social Enterprise Event at Federation Square 11 July

Are you working on a student driven project or outside of the classroom on a social or environmental idea?

Have you considered pitching your idea for funding to take your project enterprise idea to the next level?
the university SEEDS have just opened their 2012 Investment Fund and are inviting applications for projects that are led by students.
# 7  
Old 06-19-2012
Quote:
Originally Posted by maddog21
Do you mean the actual body?

---------- Post updated at 09:00 PM ---------- Previous update was at 08:51 PM ----------



It is not printing the emails one after another line by line? it is still breaking the long emails.

thanks
like this ?
Code:
# cat file
Date:
From:
Subject:
To:
Content-Type:
---body --1-2-
-----3----
-----4----
-----5----
Date:
From:
Subject:
To:
Content-Type:
----body --6 7---
----8---
----9---
Date:
From:

Code:
# awk '/Content-Type/{while(getline){if($0~/Date/)break;x=x?x" "$0:$0}print "email",++i,": " x;x=""}' file
email 1 : ---body --1-2- -----3---- -----4---- -----5----
email 2 : ----body --6 7--- ----8--- ----9---

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to split a string into array?

value=malayalam # i need to store the value in an array by splitting the character #the output i need is m a l a y a l a m Please use CODE tags for output data as well as required by forum rules! (5 Replies)
Discussion started by: Meeran Rizvi
5 Replies

2. Shell Programming and Scripting

Split the string in perl

Hi All, How to split the string KAR_Celltick_Ban_GSMGW3 and want to pickup the third filed. Sometime the string may be "KAR_Celltick_Ban" like this Thanks in advance (1 Reply)
Discussion started by: sujit_kashyap
1 Replies

3. Shell Programming and Scripting

Need to split a string

Hi, We have a SunOS 5.10 Generic_142900-13 sun4v sparc SUNW,T5240. I'm trying to find a way to split a string into 2 variables. Ex: parm1="192.168.1.101/parent/child" What I need to do is split the string above into: host="192.168.1.101" location="parent/child" I saw the... (3 Replies)
Discussion started by: adshocker
3 Replies

4. Shell Programming and Scripting

split string

Hi I am facing a problem in spitting a string. Here is the string -------------------- subject1=10;subject2=30;subject3=40;subjectcode=10001;... Now, I want only marks not the subject code. (there can be 'n' subjects) ie. 10 30 40 My doubt ---------- How do I... (5 Replies)
Discussion started by: jionnet
5 Replies

5. Shell Programming and Scripting

Split string

Hi, can we split a number like this.. if i have something like 85743975945738, can it be converted as 8574-3975-945738 in ksh shell using single command... Thanks! (5 Replies)
Discussion started by: nram_krishna@ya
5 Replies

6. Shell Programming and Scripting

split the string

I need to split the string msu1_2 It should be generic for any string of the form msu<digits>_<digits> so that i get $X =1 and $Y = 2 Please help Thanks (5 Replies)
Discussion started by: asth
5 Replies

7. Shell Programming and Scripting

Split A String

Hi, I am new to scripting and need help splitting a string using space as the delimiter. How can I do that? I want the result to be stored in an Array. I tried using set -A arr $(echo $FILE) echo $arr The result of the above was ''. Thanks. (2 Replies)
Discussion started by: newbie187
2 Replies

8. Shell Programming and Scripting

split string help

could anyone help in running split cmd split("String1,outputArray,"delimiter); with sample script?. for eg i have abc-def-ghi-sdf- my ultimate aim of asking this is i have a string containing hypens, i want to get the string before last n(2) Hypens (4 Replies)
Discussion started by: senthilk615
4 Replies

9. Shell Programming and Scripting

split a string

Hi I have a script that loops though lines of a file and reads each line in to a variable ($LINE). I want to look at the line and split it into it's constituent parts. e.g. a line might be "This is a string" I want to then have variables set to each element thus: A=This B=is C=a... (3 Replies)
Discussion started by: gazingdown
3 Replies

10. Shell Programming and Scripting

split a file at a specified string

to find log files modification, i want to select all the lines of a file behind a string (found by grep ?). :rolleyes: (6 Replies)
Discussion started by: jpl35
6 Replies
Login or Register to Ask a Question