# split string

**URL:** <https://community.unix.com/t/split-string/312130>\
**Category:** Shell Programming and Scripting\
**Created:** [June 19, 2012, 5:49am UTC](https://community.unix.com/t/split-string/312130 "2012-06-19T05:49:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![maddog21](https://community.unix.com/letter_avatar/maddog21/32/6_22734026db12803ebb3e059622ac3534.png) [@maddog21](https://community.unix.com/u/maddog21)\
**Post date:** [June 19, 2012, 5:49am UTC](https://community.unix.com/t/split-string/312130/1 "2012-06-19T05:49:53Z")

</div>

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

```nohighlight
email1: bla bla bla
bla bla bla
bal
email2: bla bla bla bal
bla bla bal

```

i want it to print

```nohighlight
email1: bla bla bal bal bal bal
email2: bla bal bla blalba bla bla

```

the code i used to print the body is

```nohighlight
awk '/Content-Type/{p=1;c++;print "Email-",c;}/Date/{p=0}p' file

```

Thank You!

---

<div class="post-metadata">

**Author:** ![ygemici](https://community.unix.com/letter_avatar/ygemici/32/6_22734026db12803ebb3e059622ac3534.png) [@ygemici](https://community.unix.com/u/ygemici)\
**Post date:** [June 19, 2012, 6:10am UTC](https://community.unix.com/t/split-string/312130/2 "2012-06-19T06:10:23Z")

</div>

what is your full input ?

---

<div class="post-metadata">

**Author:** ![elixir\_sinari](https://community.unix.com/user_avatar/community.unix.com/elixir_sinari/32/2563_2.png) [@elixir\_sinari](https://community.unix.com/u/elixir_sinari)\
**Post date:** [June 19, 2012, 6:17am UTC](https://community.unix.com/t/split-string/312130/3 "2012-06-19T06:17:01Z")

</div>

Just changing your awk program a bit:

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

```

---

<div class="post-metadata">

**Author:** ![maddog21](https://community.unix.com/letter_avatar/maddog21/32/6_22734026db12803ebb3e059622ac3534.png) [@maddog21](https://community.unix.com/u/maddog21)\
**Post date:** [June 19, 2012, 7:00am UTC](https://community.unix.com/t/split-string/312130/4 "2012-06-19T07:00:48Z")

</div>

> [@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 ----------

> [@elixir\_sinari](#):
>
> Just changing your awk program a bit:
> 
> ```plaintext
> 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

---

<div class="post-metadata">

**Author:** ![elixir\_sinari](https://community.unix.com/user_avatar/community.unix.com/elixir_sinari/32/2563_2.png) [@elixir\_sinari](https://community.unix.com/u/elixir_sinari)\
**Post date:** [June 19, 2012, 7:06am UTC](https://community.unix.com/t/split-string/312130/5 "2012-06-19T07:06:21Z")

</div>

> [@maddog21](#):
>
> It is not printing the emails one after another line by line? it is still breaking the long emails.  
> thanks

Sigh....:wall: why didn't I ask for the input before?

Please provide the input..

---

<div class="post-metadata">

**Author:** ![maddog21](https://community.unix.com/letter_avatar/maddog21/32/6_22734026db12803ebb3e059622ac3534.png) [@maddog21](https://community.unix.com/u/maddog21)\
**Post date:** [June 19, 2012, 7:36am UTC](https://community.unix.com/t/split-string/312130/6 "2012-06-19T07:36:28Z")

</div>

> [@elixir\_sinari](#):
>
> Sigh....:wall: 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.

---

<div class="post-metadata">

**Author:** ![ygemici](https://community.unix.com/letter_avatar/ygemici/32/6_22734026db12803ebb3e059622ac3534.png) [@ygemici](https://community.unix.com/u/ygemici)\
**Post date:** [June 19, 2012, 7:37am UTC](https://community.unix.com/t/split-string/312130/7 "2012-06-19T07:37:46Z")

</div>

> [@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 ?

```plaintext
# 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:

```

```plaintext
# 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---

```

---

<div class="post-metadata">

**Author:** ![maddog21](https://community.unix.com/letter_avatar/maddog21/32/6_22734026db12803ebb3e059622ac3534.png) [@maddog21](https://community.unix.com/u/maddog21)\
**Post date:** [June 19, 2012, 8:06am UTC](https://community.unix.com/t/split-string/312130/8 "2012-06-19T08:06:09Z")

</div>

thank you

---------- Post updated at 10:06 PM ---------- Previous update was at 10:02 PM ----------

thank you very much!
