Merge files and generate a resume in two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merge files and generate a resume in two files
# 1  
Old 12-02-2013
Merge files and generate a resume in two files

Dear Gents,

Please I need your help... I need small script Smilie to do the following.

I have a thousand of files in a folder produced daily.

I need first to merge all files called. txt (0009.txt, 0010.txt, 0011.txt) and and to output a resume of all information on 2 separate files in csv format (I wrote .txt only to be able to upload the files), at the output should be to files RP.csv and SP.csv , as I show in the attached files..

Thanks always for your support. Smilie
# 2  
Old 12-02-2013
So, what have you tried so far?
What language or tools are you most comfortable with?
What shell are you using?
What is your operating system and version?
What logic rules do you have for merging the files are generating the reports?

Most importantly, what have you tried so far?



Regards,
Robin
# 3  
Old 12-02-2013
Hi Robin

Thanks for your answer.

I using linux red hat 5,, shell csh

I like to use awk,

Just I start to try to di it mergin the files
using :
Code:
awk 'FNR==1{print ""}1' *.txt > tmp1

and then

I try to do
Code:
cat tmp1 | awk -F, '{print $0}' | sed '1,17d' | sed 's/_/,/g' | sed 's/,/,/g > tmp2


That is all I did.
# 4  
Old 12-02-2013
Hmmm, not sure I understand your attempts. Looking at your files, as a starting point try
Code:
awk -F, 'FNR>17 {print >$1"P.csv"}' 0*.txt

You may want to add gsub (/_/, ",", $2) before printing.

Last edited by RudiC; 12-03-2013 at 08:05 AM.. Reason: typo
This User Gave Thanks to RudiC For This Post:
# 5  
Old 12-02-2013
Hello RudiC

I am using
Code:
 awk -F, 'FNR>17  gsub (/_/, ",", $0); {print >$1"P.csv"}' 0*.txt

It create for many files like
AP.csv, CP.csv, HP.csv, YP.csv, ZP.csv and I need in the output only The RP.csv and SP.csv. How we can eliminate at the begining all the rows which start with letters A,C,Y and Z, to avoid to get these output files.

And also in the row 18 for each file there is a value that I need to recovery and to put at the end of each row.. example.
Code:
S,1915_7690_1,2013,30,18,58,37,0.000712977,0.000374325,0.93,0.000199737,0.000430314

in the output file only where the first caracter is R, we need to do:

Code:
R,1996_7571_1_2_1,2170.12,1.5,5,0.000235452,9.30413e-05,2268,6.9,12.8,20.8,1915,7690

for each line starting with R we need to append these values.. It is a reference becasue all the rows correspond to the same code.

Example
Code:
S,1915_7690_1,2013,30,18,58,37,0.000712977,0.000374325,0.93,0.000199737,0.000430314
R,1996_7571_1_2_1,2170.12,1.5,5,0.000235452,9.30413e-05,2268,6.9,12.8,20.8

In the output R file need to be included for each row.
Code:
R,1996_7571_1_2_1,2170.12,1.5,5,0.000235452,9.30413e-05,2268,6.9,12.8,20.8,1915,7690
R,1996_7572_1_2_1,2163.76,1.59,5,0.000250454,0.000103684,2260,4.9,12.8,42.5,1915,7690
R,1996_7573_1_2_1,2233.66,0.49,5,0.000250275,8.56004e-05,2252,4.9,13.8,21.7,1915,7690

Thanks a lot for your helpSmilie

I mean for each file we need to check the value in the row 18 and to append in all rows starting with R these values, For each file will be a diferent value..
# 6  
Old 12-03-2013
You lost me. Which value from line 18 (FNR==18) do you want to save and append to the respective R- lines of that file?
To eliminate the A, Y, Z line try sth like
Code:
$1~/[RS]/

# 7  
Old 12-03-2013
Dear RudiC
Sorry to confuse you , What I need is only to get at the end of each R line are:
Example
line 18
Code:
S,1915_7690_1,2013,30,18,58,37,0.000712977,0.000374325,0.93,0.000199737,0.000430314

line 19
Code:
R,1996_7571_1_2_1,2170.12,1.5,5,0.000235452,9.30413e-05,2268,6.9,12.8,20.8

I need to take these values from line 18
Code:
1915_7690

to append all lines with R
Code:
R,1996_7571_1_2_1,2170.12,1.5,5,0.000235452,9.30413e-05,2268,6.9,12.8,20.8,1915,7690

For each file there is differente value in line 18, need to be append in lines with R
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate E-Mails with content on different files

Hello, I am using a script to create a random password for a user. The file looks like user1:thepassword1 user2:thepassword2 user3:thepassword3 Passwords are openssl passwd hashed. I have an own file where the password is written in cleartext. Now i want to send an E-Mail to the... (8 Replies)
Discussion started by: Manu_H
8 Replies

2. UNIX for Beginners Questions & Answers

Umask to generate files with rwx permissions for all

i need my script1.sh to generate /tmp/temp.txt with full permissions i.e -rwxrwxrwx 1 user1 users 23 Dec 16 10:52 /tmp/temp.txtmore script1.sh umask 666 echo "hello">/tmp/temp.txt But the script1.sh generates temp.txt with different permissions as shown below. -rwxr-xr-x 1 user1 users... (6 Replies)
Discussion started by: mohtashims
6 Replies

3. Shell Programming and Scripting

Checking in a directory how many files are present and basing on that merge all the files

Hi, My requirement is,there is a directory location like: :camp/current/ In this location there can be different flat files that are generated in a single day with same header and the data will be different, differentiated by timestamp, so i need to verify how many files are generated... (10 Replies)
Discussion started by: srikanth_sagi
10 Replies

4. Shell Programming and Scripting

Generate files from one file based on lines

Hi Friends, I have a file1 file1.txt 1ABC 13478 aqjerh 473 343 2hej 478 5775 24578 23892 3fhd fg 847 brjkb f99345 487 4eh ehjk 84 47589 8947 234 5784 487 738 52895 8975 6 57489 eghe9 4575 859479 7fnbd 4y5 4iuy 458 h irh 8fjdg 74 7845 8475 5789 94yr 48yr 4hr erhj reh... (3 Replies)
Discussion started by: i150371485
3 Replies

5. Shell Programming and Scripting

How to use perl to generate files with correct filenames?

Hi, I'm trying to use perl to generate files based on sections in a large textfile. This will create one file per section that starts with " ABC_": perl -n -e '/^ABC_/ and open FH, ">output_".$n++; print FH;' largefile.txt However, the output filenames will be on the form output_nn. This... (2 Replies)
Discussion started by: Yagi Uda
2 Replies

6. UNIX for Dummies Questions & Answers

Generate list of deleted files

I copied all JPEGs from my laptop to an external drive using find . -name "*.jpg" -exec cp '{}' ./media/Backup/pictures \; And then deleted all of them from my laptop. Now, I realize that I need the folder path of all the original JPEGs as the path has the important information. I dont... (1 Reply)
Discussion started by: eshwaconsulting
1 Replies

7. Shell Programming and Scripting

Merge files of differrent size with one field common in both files using awk

hi, i am facing a problem in merging two files using awk, the problem is as stated below, file1: A|B|C|D|E|F|G|H|I|1 M|N|O|P|Q|R|S|T|U|2 AA|BB|CC|DD|EE|FF|GG|HH|II|1 .... .... .... file2 : 1|Mn|op|qr (2 Replies)
Discussion started by: shashi1982
2 Replies

8. What is on Your Mind?

Are companies viewing my resume? How do I track my resume visits?

Hi everybody, I am wondering if there is any tool or website out there which can track who is viewing my resume. It is very frustrating when you send your CV or Cover Letter and you receive no feedback from the company, you don't even know if they have checked it out. Thanks for your help (1 Reply)
Discussion started by: gearyipswich
1 Replies

9. Shell Programming and Scripting

Help generate report from log files

Hi Expert, I have some confusing to generate report from the log file as shown below: filename :test1.log start_time date end_time number code P 000029.621 20070823 000029 12134567890 111111111111 00 0 000 003... (4 Replies)
Discussion started by: bucci
4 Replies

10. Shell Programming and Scripting

how to generate a list of files

Hello people I need to find a way to generate a file that contains the names of all *.jpg files that were generated after a specific date The search should start in my current folder and recursively search inner folders It would be best to list the file names one below the other in the output... (3 Replies)
Discussion started by: jasongr
3 Replies
Login or Register to Ask a Question