How to find strings in multiple lines of txt file then add all to new csv line

  Kiến thức lập trình

I have thousands of txt files that were converted from emails that included a “Contact Us” form. I need to find/select strings in the second “column”, but the number of lines to start each email are variable. It seems that the columns are tab delimited. To boot, the last field in the contact form spans multiple lines and some of the emails have pipe symbols “|” that seem to have been created since I used html2text to convert these to txt files. How can I extract the values of the “First Name”, “Last Name”, and “Long Text” fields? Ultimately these will be added as a new line in a csv.

<variable number of lines at start of email

..>
|First Name Bob |
|Last Name Jones |
|
|Long Text laksjdflkjasldkf jlaksjdf flkjalskd fasgafg asdfj |
asdfasdfsadf a adfasdf asdfasdfasg asdgsfg asdgfa|
asgretg ergsdfgth erghsdfgwerg ergsdfgsg ergsdfgre |

Using awk, below is not very effective, probably because of the space in First Name and Last Name but putting this in quotes did not work

awk -F'First Name|Last Name' '{print $2}' 1.txt

And I am really not sure how to approach the Long Text field as below only prints one line and not all the text that I need

awk -F'Long Text' '{print $2}' 1.txt

It seems using awk with tab field separator could be possible but I have not gotten very far trying that.

New contributor

Aidbfbx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT