Results 1 to 6 of 6

Thread: Manipulating text files

  1. #1

    Default Manipulating text files

    OK. It's been a long time since I did any of this text manipulation stuff, and then only on my last OS, OS/2, quite a few years ago

    I have a couple of thousand text files all in the same name format user@emailaddress.dat. Inside each file I need the first two items and the last item on the first line which is delimited by "|". I want to copy these two items and the last item for all files into one file, delimited by a tab, each files data to be on a new line.

    How to do this?

  2. #2

    Default Re: Manipulating text files

    OK. I got the first piece of content into a datafile, by doing it manually. I now need to add the 2nd and last piece of data to the file. Or if it's better to start over, I will

  3. #3

    Default Re: Manipulating text files

    Quote Originally Posted by stubble View Post
    OK. I got the first piece of content into a datafile, by doing it manually. I now need to add the 2nd and last piece of data to the file. Or if it's better to start over, I will
    May be something like this cat <file> | awk '{ print $5, "\tIN\tPTR\t", $1 }'
    can help.
    I used it as a part of command to compose reverse dns zone.

  4. #4
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    19,581
    Blog Entries
    14

    Default Re: Manipulating text files

    First I would see that I would get all the first lines of the files in /pathtofiles into one bigger one, "collectedfirstlines.txt":
    Code:
    for i in `ls /pathtofiles/*.dat`; do
      head -1 $i >> /pathtofiles/collectedfirstlines.txt
    done
    Then I would try to see if LibreOffice Calc can open it and convert it.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    https://en.opensuse.org/openSUSE:Board#Members
    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  5. #5
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Manipulating text files

    On 2012-02-08 02:36, stubble wrote:
    >
    > OK. It's been a long time since I did any of this text manipulation
    > stuff, and then only on my last OS, OS/2, quite a few years ago


    With a combination of 'head' and 'tail' you can get any line of the file.
    Then with 'cut' you can extract fields.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 11.4 x86_64 "Celadon" at Telcontar)

  6. #6

    Default Re: Manipulating text files

    Thanks Knurpht. A variation on that did the trick. The spread sheet took some editing for more than one word answers (which went into separate cells.. a problem with the formatting of the file from the previous program), but it did the trick and I was able to import my users into another program's database. It went quite well. Thank you and to all others who replied.

Posting Permissions

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