LinuxQuestions.org
Visit the LQ Articles and Editorials section
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, 01:43 PM   #1
bfay
LQ Newbie
 
Registered: Sep 2003
Location: Quebec, Canada
Distribution: Debian
Posts: 21

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, 04:40 AM   #2
kooru
Senior Member
 
Registered: Sep 2012
Location: Italy
Distribution: Slackware, NetBSD
Posts: 1,371
Blog Entries: 5

Rep: Reputation: 270Reputation: 270Reputation: 270
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 04:43 AM.
 
Old 03-02-2013, 08:41 PM   #3
bfay
LQ Newbie
 
Registered: Sep 2003
Location: Quebec, Canada
Distribution: Debian
Posts: 21

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10:08 AM
How to show specific lines in a text file in Linux. thamann Linux - Newbie 12 02-03-2011 04:04 PM
Join lines in text file vidyashankara Linux - General 10 12-21-2009 04:17 PM
join every three lines of a text file powah Programming 8 02-02-2007 12:40 AM
Read specific lines from a text file chobin Programming 8 06-14-2006 12:14 PM


All times are GMT -5. The time now is 12:32 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration