0

I have a text file (name, surname, phone number) than I would import in excel and the play with column (name, surname...)

The file was previously a docx file. I've converted it on as a text file. But the converted txt file, has a strange format: Repeated 6 lines block, with each field (name, surname, phone, town)

xxx
yyy
999
zzz
xxx1
yyy1

repeated more times. I would compact each block in a single line and separate field by space. NOTE that xxx1 and yyy1 are name and surname of next person So I can import it in Excel, taking space as a separator column.

How can I do that? I know I can do that in Lisp, but I do not know how.

  • 1
    You say "Repeated 6 lines block" but you mention 4 parts to each block. Could you clarify how to reconcile this 4 vs 6 discrepency? – Stefan Jan 8 at 13:34
0

IIUC you could do that with a keyboard macro.

Place the cursor at the beginning i.e. the very first x.

Define the macro (and also transform the first block):

C-x (
C-SPC
C-n
C-n
C-n
M-%
C-q C-j RET
SPC RET
!
C-n
C-a
C-x )

Transform the rest by calling the macro until it fails.

C-u 0 C-x e
|improve this answer|||||
0

I would try with sed (unix utility) and regular expressions.

|improve this answer|||||
  • I don't think you can do this[1] with sed, at least not easily. awk might be a more reasonable suggestion, but remember, this is an emacs group and the OP asked for a lisp solution (although I have been guilty of suggesting non-lisp, non-emacs solutions a couple of times in the past too :-) ). [1]BTW, it's not clear what "this" is: the question is unclear. – NickD Jan 10 at 4:24
  • 1
    With some bad faith: awk is in Emacs through eshell. – Pierre ALBARÈDE Jan 10 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.