Results 1 to 5 of 5

Thread: split string

  1. #1
    Join Date
    Jun 2012
    Beans
    4

    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

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

    i want it to print

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

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

    Thank You!

  2. #2
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: split string

    You can use tr to substitute new-line with space. You can easily pipe via tr.

    Code:
    tr '\n' ' '  < file-with-several-lines.txt

  3. #3
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: split string

    You can try up something like below .

    Code:
    awk '/email/{c++}{print > "file" c}' emaildata_file
    The above would strip out email bodies and place them into files file1 , file2 ..etc .
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

  4. #4
    Join Date
    Jun 2012
    Beans
    4

    Re: split string

    Quote Originally Posted by codemaniac View Post
    You can try up something like below .

    Code:
    awk '/email/{c++}{print > "file" c}' emaildata_file
    The above would strip out email bodies and place them into files file1 , file2 ..etc .

    how can i make this in to a script where it reads from one file and outputs to different file?

    thanks

  5. #5
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: split string

    Quote Originally Posted by maddog21 View Post
    how can i make this in to a script where it reads from one file and outputs to different file?

    thanks
    You can put the above awklet in a bash script and execute.

    Code:
    #!/bin/bash
    
    awk '/email/{c++}{print > "file" c}' emaildata_file
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •