UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 27th, 2011, 03:51 PM
frywonton frywonton is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 4 frywonton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 2 sec
Reputation Power: 0
Cool How to paste two words in a file without space

Hi Experts:

I need your assistance in using paste to join two words together. Here I have two files:
file1: Word
file2: /strings together

Using paste command in unix:
paste file1 file2 > file3
Output from file3: Word /strings together

Note: There are spaces between Word and /strings

I would like them to be like this
Word/strings together

Any assistance in how to get this to work in unix is greatly appreciated.

Thanks,

Frywonton

Reply With Quote
  #2  
Old August 27th, 2011, 10:23 PM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 41 m
Reputation Power: 1485
That seems to be how paste works, but you might be able to get it to drop the tab character it uses (by default) as the replacement to file1's newlines by usind -d '' to have the delimiter be 'blank'. I've not tested that so cannot be sure it will work.
Failing that an alternate method could be used - either continue to use paste and use a 'strange' delimiter and then use sed or tr to edit out that character (so choose one you'd never see), or use a different method of concatentation entirely. Most methods would require you to deal with the (potential) newline at the end of file1 at some stage of the process.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
  #3  
Old August 27th, 2011, 10:49 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,375 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 12 h 5 m 23 sec
Reputation Power: 383
Works

This is longer than paste but works in my tests:

Code:
gawk 'FILENAME==ARGV[1]{a[i++]=$0}FILENAME==ARGV[2]{printf"%s%s",a[j++],$0;print""}' firstFile secondFile


(I was too lazy to figure out how many back slashes are needed to stick a \n into the string on the command line. That's why I instead used a separate print"" .)

Reply With Quote
  #4  
Old August 28th, 2011, 08:31 AM
frywonton frywonton is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 4 frywonton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 2 sec
Reputation Power: 0
Thumbs up

Thanks Simon and b49P23TIvg for your prompt reply.
Simon, I have been pulling my hair trying to figure out to use the type to joint without sucess. I am a newbie but willing to learn.

Thanks b49P23TIvg! Your gwak scripts works. I will try and implement it to my other program. Greatly appprecaited your alternative solution. Thanks to both of you for your reply.

Quote:
Originally Posted by b49P23TIvg
This is longer than paste but works in my tests:

Code:
gawk 'FILENAME==ARGV[1]{a[i++]=$0}FILENAME==ARGV[2]{printf"%s%s",a[j++],$0;print""}' firstFile secondFile


(I was too lazy to figure out how many back slashes are needed to stick a \n into the string on the command line. That's why I instead used a separate print"" .)

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > How to paste two words in a file without space

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap