File concatenation problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File concatenation problem
# 1  
Old 07-18-2005
File concatenation problem

I have written a script to find particular text files created within the last 24 hours and concatenate them all into a single concat.txt file. The problem that I am running into is that the last line of the text files do not terminate with <CR><LF> characters (as do all the other lines in each file). The lack of line termination characters at the end of the last lines causes the files to 'wrap' together: line1 of file2 is appended to the end of the last line of file1, and line 1 of file3 is appended to the end of file 2, etc. (This file format has given me alot grief overall with other things, since for instance tail doesn't work right if line don't have \n at the end, etc.)

Anyway, to resolve this, I wrote the code below to append a <newline> character to the end of each file as files are concatenated. This works except that it results in a single blank line between each file, that I have to remove using sed. I don't understand why I'm getting blank lines since without the added \n, the lines wrapped together.

Here's my code:

find ${ARCH_DIR} -name 'AA20*txt' -ctime -${DAYSCNT} -exec cat {} \; -exec echo "\n" \; >> ${CATFILENAME}

sed '/^$/d' $CATFILENAME > $TEMPFILE

Is there an easier and better way to concatenate text files that have no line termination characters at the end of the last line, especially one that doesn't add blank lines?

Any help would be much appreciated.
# 2  
Old 07-18-2005
maybe something like this - not tested:
Code:
find ${ARCH_DIR} -name 'AA20*txt' -ctime -${DAYSCNT} \; | xargs -l (cat; echo '')>> ${CATFILENAME}

# 3  
Old 07-18-2005
echo is adding two carriage returns - one for the character.

change echo "\n" to echo " " or change the parms to echo to suprress the second \n
# 4  
Old 07-18-2005
I changed the echo to echo "" and it works great. Thanks VERY much! Smilie Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Concatenation of multiple files based on file pattern

Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR" "Report.Dddmmyy.Thhmiss.ACCD" "Report.Dddmmyy.Thhmiss.BCCD" "Report.Dddmmyy.Thhmiss.CCCD"... (1 Reply)
Discussion started by: Jesshelle David
1 Replies

2. Shell Programming and Scripting

Issue in Concatenation/Joining of lines in a dynamically generated file

Hi, I have a file containing many records delimited by pipe (|). Each record should contain 17 columnns/fields. there are some fields having fields less than 17.So i am extracting those records to a file using the below command awk 'BEGIN {FS="|"} NF !=17 {print}' feedfile.txt... (8 Replies)
Discussion started by: TomG
8 Replies

3. Shell Programming and Scripting

File concatenation

awk '{$2=$2":"$8"-"$3;$3=$NF;$4=$NF="";print $0 | $10=$10":"$8"-"$18;$11=$NF;$12=$NF="";print $0 }' design.txt Trying to concatenate specific fields in a spreadsheet and the others remain unchanged. I attached an excel spreadsheet (all the data comes from a design.txt), but I put an example... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

File Concatenation in a format

I have some files named as: error_abc.txt error_def.txt error_ghi.txt I want to concatenate all these into a single file say error_all.txt. The error_all.txt should be displayed like: ... (11 Replies)
Discussion started by: ankur328
11 Replies

5. Shell Programming and Scripting

String variable concatenation through loop problem

Hi Team!! Please can anyone tell me why the following line does not work properly? str3+=$str2 it seems that str3 variable does not keep its value in order to be concatenated in the next iteration! Thus when i print the result of the line above it returns the str2 value What i want to do is to... (8 Replies)
Discussion started by: paladinaeon
8 Replies

6. Shell Programming and Scripting

Erroneous file concatenation.

I have more than one files in a directory , namely GLOW_OUT.txt FIELD_OUT.txt BASE_OUT.txt ... SHOW_OUT.txt What I wanted to do is to I am working in Korn Shell What I did was : for file in <directory_name>/*.* ;do cat $file | grep -v '^$' >> temp_file rm $file done ... (7 Replies)
Discussion started by: kumarjt
7 Replies

7. Shell Programming and Scripting

String concatenation problem

Hi there, I'm writing a basic script where I want to make a string of 2 numeric fields from a file, which I have done, but the behavior is rather confusing. I have a file of random values such as: 1 2 3 4 5 6 7 8 9 10 and my awk code is: BEGIN { FS = " " } { str = str $1 $2 } END {... (7 Replies)
Discussion started by: HMChadwick
7 Replies

8. Shell Programming and Scripting

Sed line concatenation problem

I have a somewhat bizarre problem when trying to concatenate lines in a file. Using cat file.txt | sed -e :a -e '/$/N;s/\n/ /;ta' the output in file.txt should go from 1 2 3to 1 2 3 instead I only get the last line or 3. I find that if I open the file in gedit and hit delete in front of every... (7 Replies)
Discussion started by: pluto7777
7 Replies

9. Shell Programming and Scripting

Concatenation

How can I do this: date = 4 -----------> 04 Month= 3-----------> 03 I wish to make a varibale named Var1 which will hold the value of current date and month value as: 2 digits for date. 2 digits for month. So finally var1 should hold value as 0403 --- MMDD (11 Replies)
Discussion started by: Asteroid
11 Replies

10. UNIX for Dummies Questions & Answers

File Concatenation

Hi, I want to write a generic shell script, which can concatenate n number of files passed as parameter ;to an output file which is again a parameter Example catfl.sh outfl.txt a.txt b.txt c.txt (3 files to be concatenated into a file outfl.txt) catfl.sh outfl.txt a.txt b.txt(2 files to be... (3 Replies)
Discussion started by: samit_9999
3 Replies
Login or Register to Ask a Question