Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-07-2012
Registered User
 

Join Date: Sep 2011
Posts: 12
Thanks: 19
Thanked 0 Times in 0 Posts
join two lines

I want to join this two lines but only when after him
I have nothing or a comma

Yes, I know Jonesy, and I'll give him
about one more minute.

this two lines must become
Yes, I know Jonesy, and I'll give him about one more minute.


thank you very much
Sponsored Links
    #2  
Old 02-07-2012
Registered User
 

Join Date: Nov 2009
Location: BeiJing China
Posts: 146
Thanks: 12
Thanked 46 Times in 31 Posts

Code:
cat infilke | xargs -d '\n'

The Following User Says Thank You to huaihaizi3 For This Useful Post:
thailand (02-08-2012)
Sponsored Links
    #3  
Old 02-07-2012
Scrutinizer's Avatar
mother ate her
 

Join Date: Nov 2008
Location: Amsterdam
Posts: 5,371
Thanks: 80
Thanked 1,107 Times in 1,011 Posts

Code:
sed '/[^[:punct:]],*$/{N;s/\n/ /;}' infile


Code:
awk '/[^[:punct:]],*$/{getline $(NF+1)}1' infile

The Following User Says Thank You to Scrutinizer For This Useful Post:
thailand (02-08-2012)
    #4  
Old 02-08-2012
Registered User
 

Join Date: Sep 2011
Posts: 12
Thanks: 19
Thanked 0 Times in 0 Posts
the input is like this

This is my cat
my cat's name is betty

This is my dog
my dog's name is frank

This is my fish
my fish's name is george

This is my goat
my goat's name is adam

when I use xargs then the output is
my goat's name is adamge

when I use sed or awk then the output is
my cat's name is betty
This is my dog
y dog's name is frank
my fish's name is george
This is my goat
y goat's name is adam

but the output must be this
--------------------------------------
This is my cat my cat's name is betty

This is my dog my dog's name is frank

This is my fish my fish's name is george

This is my goat my goat's name is adam

thank you
Sponsored Links
    #5  
Old 02-08-2012
Scrutinizer's Avatar
mother ate her
 

Join Date: Nov 2008
Location: Amsterdam
Posts: 5,371
Thanks: 80
Thanked 1,107 Times in 1,011 Posts
I presume you mean the other way around.. See if this works:

Code:
awk '/[^[:punct:]],*$/{getline $(NF+1)}NF' infile

or perhaps even this (if every sentence is a paragraph that ends with an empty line)..

Code:
awk '$1=$1' RS= infile

The Following User Says Thank You to Scrutinizer For This Useful Post:
thailand (02-09-2012)
Sponsored Links
    #6  
Old 02-09-2012
Registered User
 

Join Date: Jul 2011
Posts: 84
Thanks: 0
Thanked 16 Times in 15 Posts
try this


Code:
xargs -L 2 < filename.txt

The Following 2 Users Say Thank You to tarun_agrawal For This Useful Post:
Scrutinizer (02-09-2012), thailand (02-09-2012)
Sponsored Links
    #7  
Old 02-09-2012
balajesuri's Avatar
#! /bin/bash
 

Join Date: Apr 2009
Location: India
Posts: 1,019
Thanks: 9
Thanked 285 Times in 277 Posts

Code:
perl -ne 'if (/^\s+/){print "\n\n"}else{chomp;print "$_ "}' inputfile

The Following User Says Thank You to balajesuri For This Useful Post:
thailand (02-09-2012)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
join 2 lines maxim42 Shell Programming and Scripting 8 03-02-2010 07:22 PM
Join the lines Beginer0705 Shell Programming and Scripting 8 09-30-2009 02:42 AM
join lines repinementer Shell Programming and Scripting 2 09-19-2009 02:53 AM
how to join lines glamo_2312 UNIX for Dummies Questions & Answers 8 09-16-2008 04:17 AM
join two lines together tine Shell Programming and Scripting 4 12-12-2003 11:34 AM



All times are GMT -4. The time now is 04:32 AM.