LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (http://www.linuxquestions.org/questions/general-10/)
-   -   Join two specific lines in a text file (http://www.linuxquestions.org/questions/general-10/join-two-specific-lines-in-a-text-file-4175452285/)

bfay 03-01-2013 12:43 PM

Join two specific lines in a text file
 
Hi,

I have a large file composed of questions and answers. Most of the questions are split on two lines, for example:
How to we do
something with Linux?
I would like to join those those lines with the help of a script to have:
How to we do something with Linux?
How could we script something to join those lines? My guest is with awk but besides spelling it, I know nothing about it.

Thanks,
Bernard

kooru 03-02-2013 03:40 AM

If your file is as this (named yourfile.txt):

How to we do
something with Linux?
anwer...
how are
you?
anwser
do you
like music?
answer

try with

Code:

awk 'NR==1{printf $0;next}
/\?$/{printf " " $0;next}
{printf "\n" $0}
END{print ""}
' yourfile.txt


bfay 03-02-2013 07:41 PM

I gave it a try and got the following error:

Quote:

What is the meaning of the term "time constant" in an RL circuit?awk: (FILENAME=ric8-questions.txt FNR=4) fatal: not enough arguments to satisfy format string
`
The time required for the current in the circuit to build up to 36.8% of the maximum value '
^ ran out for this one
If it may make a difference, the file looks more like:
Quote:

How to we do
something with Linux?
answer
answer
answer
how are
you?
answer
answer
answer
answer
do you
like music?
answer
answer
answer

Thanks for your help. I will have to find a good tutorial to understand awk, once and for all.


All times are GMT -5. The time now is 06:33 AM.