LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 03-01-2013, 12:43 PM   #1
bfay
LQ Newbie
 
Registered: Sep 2003
Location: Quebec, Canada
Distribution: Debian
Posts: 22

Rep: Reputation: 15
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
 
Old 03-02-2013, 03:40 AM   #2
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 275Reputation: 275Reputation: 275
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

Last edited by kooru; 03-02-2013 at 03:43 AM.
 
Old 03-02-2013, 07:41 PM   #3
bfay
LQ Newbie
 
Registered: Sep 2003
Location: Quebec, Canada
Distribution: Debian
Posts: 22

Original Poster
Rep: Reputation: 15
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
parsing text file in C++ and read specific lines Alkass Linux - Newbie 4 12-16-2012 09:08 AM
How to show specific lines in a text file in Linux. thamann Linux - Newbie 12 02-03-2011 03:04 PM
Join lines in text file vidyashankara Linux - General 10 12-21-2009 03:17 PM
join every three lines of a text file powah Programming 8 02-01-2007 11:40 PM
Read specific lines from a text file chobin Programming 8 06-14-2006 11:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 05:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration