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.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
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
2. Shell Programming and Scripting
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
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
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
5. Shell Programming and Scripting
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
6. Shell Programming and Scripting
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
7. Shell Programming and Scripting
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
8. Shell Programming and Scripting
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
9. Shell Programming and Scripting
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
10. UNIX for Advanced & Expert Users
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
LEARN ABOUT OPENSOLARIS
concat
concat(1T) Tcl Built-In Commands concat(1T)
__________________________________________________________________________________________________________________________________________________
NAME
concat - Join lists together
SYNOPSIS
concat ?arg arg ...?
_________________________________________________________________
DESCRIPTION
This command joins each of its arguments together with spaces after trimming leading and trailing white-space from each of them. If all
the arguments are lists, this has the same effect as concatenating them into a single list. It permits any number of arguments; if no args
are supplied, the result is an empty string.
EXAMPLES
Although concat will concatenate lists (so the command:
concat a b {c d e} {f {g h}}
will return "a b c d e f {g h}" as its result), it will also concatenate things that are not lists, and hence the command:
concat " a b {c " d " e} f"
will return "a b {c d e} f" as its result.
Note that the concatenation does not remove spaces from the middle of its arguments, so the command:
concat "a b c" { d e f }
will return "a b c d e f" (i.e. with three spaces between the a, the b and the c).
SEE ALSO
append(1T), eval(1T)
KEYWORDS
concatenate, join, lists
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+--------------------+-----------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+--------------------+-----------------+
|Availability | SUNWTcl |
+--------------------+-----------------+
|Interface Stability | Uncommitted |
+--------------------+-----------------+
NOTES
Source for Tcl is available on http://opensolaris.org.
Tcl 8.3 concat(1T)