The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
separating comma delimited words rider29 Shell Programming and Scripting 4 09-02-2009 10:12 AM
merging similar columns in a single line file repinementer Shell Programming and Scripting 7 05-28-2009 03:41 AM
Converting Space delimited file to Tab delimited file jeevs81 UNIX for Dummies Questions & Answers 16 02-26-2009 02:49 AM
replace space or spaces in a line of a file with a single : NewSolarisAdmin Shell Programming and Scripting 5 01-27-2009 02:48 PM
Searching for text in a Space delimited File andyblaylock UNIX for Dummies Questions & Answers 6 11-27-2007 07:33 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 1 Week Ago
Lucky Ali Lucky Ali is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 14
Merging files into a single tab delimited file with a space separating

I have a folder that contains say 50 files in a sequential order:
Code:
cdf_1.txt
cdf_2.txt
cdf_3.txt
cdf_3.txt
.
.
.
cdf_50.txt.
I need to merge these files in the same order into a single tab delimited file.

I used the following shell script:
Code:
for x in {1..50};
  do cat cdf_${x}.txt >> All.txt;
done
This will merge the files in the same order and out put the All.txt.

What I need is to give a space between the contents of files in the All.txt so that I could know the contents of each file separately in the All.txt.

Is there a way to modify the above shell script to give a space between the content of every file?

Please let me know.

Last edited by radoulov; 1 Week Ago at 05:33 PM.. Reason: added code tags
  #2 (permalink)  
Old 1 Week Ago
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Something like this:

Code:
for f in cdf_*.txt; do
  printf '%s\n\n' "$(<"$f")"
done > All.txt
  #3 (permalink)  
Old 1 Week Ago
steadyonabix steadyonabix is offline
Registered User
  
 

Join Date: Oct 2009
Location: UK
Posts: 154
If you are looking to put just one line between each file catted then try this

Code:
for x in {1..50}
do
  cat cdf_${x}.txt >> all.txt
  echo >> all.txt
done
  #4 (permalink)  
Old 6 Days Ago
TonyLawrence TonyLawrence is offline
Registered User
  
 

Join Date: Sep 2007
Location: SE Mass
Posts: 133
Or (a little easier if you are doing many things):
Code:
for x in {1..50}
do
  cat cdf_${x}.txt 
  echo 
done > all.txt
and you do need bash 3 for that loop to work; older shells might be able to use "seq",
Sponsored Links
Reply

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0