Merging files into a single tab delimited file with a space separating


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merging files into a single tab delimited file with a space separating
# 1  
Old 11-13-2009
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; 11-13-2009 at 05:33 PM.. Reason: added code tags
# 2  
Old 11-13-2009
Something like this:

Code:
for f in cdf_*.txt; do
  printf '%s\n\n' "$(<"$f")"
done > All.txt

# 3  
Old 11-13-2009
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  
Old 11-14-2009
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",
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace a column in tab delimited file with column in other tab delimited file,based on match

Hello Everyone.. I want to replace the retail col from FileI with cstp1 col from FileP if the strpno matches in both files FileP.txt ... (2 Replies)
Discussion started by: YogeshG
2 Replies

2. Shell Programming and Scripting

Output file with <Tab> or <Space> Delimited

Input file: xyz,pqrs.lmno,NA,NA,NA,NA,NA,NA,NA abcd,pqrs.xyz,NA,NA,NA,NA,NA,NA,NA Expected Output: xyz pqrs.lmno NA NA NA NA NA NA NA abcd pqrs.xyz NA NA NA NA NA NA NA Command Tried so far: awk -F"," 'BEGIN{OFS=" ";} {print}' $File_Path/File_Name.csv Issue:... (5 Replies)
Discussion started by: TechGyaann
5 Replies

3. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

4. Shell Programming and Scripting

How to convert space&tab delimited file to CSV?

Hello, I have a text file with space and tab (mixed) delimited file and need to convert into CSV. # cat test.txt /dev/rmt/tsmmt32 HP Ultrium 6-SCSI J3LZ 50:03:08:c0:02:72:c0:b5 F00272C0B5 0/0/6/1/1.145.17.255.0.0.0 /dev/rmt/c102t0d0BEST /dev/rmt/tsmmt37 ... (6 Replies)
Discussion started by: prvnrk
6 Replies

5. Shell Programming and Scripting

How to remove alphabets/special characters/space in the 5th field of a tab delimited file?

Thank you for 4 looking this post. We have a tab delimited file where we are facing problem in a lot of funny character. I have tried using awk but failed that is not working. In the 5th field ID which is supposed to be a integer only of that file, we are getting corrupted data as below. I... (12 Replies)
Discussion started by: Srithar
12 Replies

6. Shell Programming and Scripting

How to make tab delimited file to space delimited?

Hi How to make tab delimited file to space delimited? in put file: ABC kgy jkh ghj ash kjl o/p file: ABC kgy jkh ghj ash kjl Use code tags, thanks. (1 Reply)
Discussion started by: jagdishrout
1 Replies

7. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

8. Shell Programming and Scripting

Merging the flat files into a single file

Hi, My requirement is search for the flat files in the location that are generated in a day and merge them into a single flat file. In the merged file as well particular column value should go into particular column. awk 'NR=1 FNR>1' $(ls -rt flatfile1_v_*) when i use this command for... (4 Replies)
Discussion started by: srikanth_sagi
4 Replies

9. UNIX for Dummies Questions & Answers

How to echo space or tab delimited values into rows?

Hi, I have the following code: LIST=`ls | grep '.sql$'` echo $LIST The above code will give me something like.. file1.sh file2.sh file3.sh file4.sh file5.sh I want to display the values into rows using echo like... file1.sh file2.sh (5 Replies)
Discussion started by: adshocker
5 Replies

10. UNIX for Dummies Questions & Answers

Converting Space delimited file to Tab delimited file

Hi all, I have a file with single white space delimited values, I want to convert them to a tab delimited file. I tried sed, tr ... but nothing is working. Thanks, Rajeevan D (16 Replies)
Discussion started by: jeevs81
16 Replies
Login or Register to Ask a Question