Erroneous file concatenation.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Erroneous file concatenation.
# 1  
Old 02-18-2013
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
Quote:
MERGE DATA FROM ALL THE INDIVIDUAL FILES INTO A SINGLE FILE (temp_file), AND THEN REMOVE THE INDIVIDUAL FILES FROM THE DIRECTORY
I am working in Korn Shell

What I did was :
Code:
for file in <directory_name>/*.* ;do
 cat $file | grep -v '^$' >> temp_file 
 rm $file
done

The files get deleted BUT THE temp_file DOES NOT CONTAIN DATA FROM THE CONSTITUENT FILES.

Can any one please help me on this ?

Thanks
Kumarjit.

Last edited by kumarjt; 02-18-2013 at 11:32 AM.. Reason: Need to add shell detail
# 2  
Old 02-18-2013
In which directory were you when you executed your for loop?
# 3  
Old 02-18-2013
Rather too busy but like the man said, maybe the relative paths were bogus:
Code:
fl=$( find <directory_name>/*.* -type f )
if [ "$fl" != "" ]
 then
  grep -v '^$' $fl > temp_file
  rm $fl
 fi


Last edited by DGPickett; 02-18-2013 at 01:54 PM..
# 4  
Old 02-18-2013
I cannot find something wrong in the original post!

*.* only matches file names with a ., so cannot match temp_file,
and one can even improve efficiency:
Code:
for file in <directory_name>/*.* ;do
 cat "$file"
 rm -f "$file"
done | grep -v '^$' > temp_file

(The | grep ... discards empty lines.)
# 5  
Old 02-19-2013
Quote:
I cannot find something wrong in the original post!
That is why I asked where was (dir.) when the script is executed, IMHO only obvious reason I see is No write privilege where he is...
# 6  
Old 02-19-2013
Well, we are overdue for some feedback before we talk into the void any more!
# 7  
Old 02-19-2013
@vbe and DGPickett -
I am executing the script from a directory which is different than the <directory_name> .

One more thing :
The code actually written was :
Code:
for file in <directory_name>/*.* ;do
 cat $file | grep -v '^$' >> <directory_name>/temp_file 
 rm $file
done

Login or Register to Ask a Question

Previous Thread | Next Thread

8 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. Programming

erroneous output

#include<stdio.h> int main () { FILE* f_read; FILE* f_write; char *string; f_read=fopen("file1","r"); while(!feof(f_read)); { fscanf(f_read,"%s",string); fprintf(stdout,"%s\n",string); ... (2 Replies)
Discussion started by: bishweshwar
2 Replies

6. 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

7. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: jvander
3 Replies

8. UNIX for Dummies Questions & Answers

Deleting a File with an Erroneous Period

Hi - I am new to the Unix environment and have encountered a problem I can't resolve. I inadvertently created a data file with a period/dot at the end of the word 'dat', I.e. filename.dat. and can't remove it using the 'rm' command. In attempting to do so, I receive a message reading that the... (3 Replies)
Discussion started by: PLF
3 Replies
Login or Register to Ask a Question