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 :slight_smile:

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?

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 :slight_smile:

May be something like this cat <file> | awk ‘{ print $5, " IN PTR ", $1 }’
can help.
I used it as a part of command to compose reverse dns zone.

First I would see that I would get all the first lines of the files in /pathtofiles into one bigger one, “collectedfirstlines.txt”:


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.

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 :slight_smile:

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)

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.