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
# 8  
Old 12-03-2013
Well, then try
Code:
awk -F, 'FNR<18 || $1 !~ /[RS]/ {next}
                                {gsub (/_/,",")}
         FNR==18                {A=$2;B=$3}
                                {$(NF+1)=A
                                 $(NF+1)=B
                                 print > $1"P.csv"}
        ' OFS="," file

This User Gave Thanks to RudiC For This Post:
# 9  
Old 12-03-2013
Dear RudiC,

Thanks a lot for your help.

Please only the last thing, how we can append also the name of the file at the last of each line for both files RP.csv and SP.csv.

Example

Code:
R,1996_7566_1_2_1,2168.85,1.09,5,0.000323826,0.000241978,692,7.9,12.8,16.8,1915,7685,9

Code:
S,1915_7685_1,2013,30,18,54,34,0.000909391,0.000410113,0.93,0.000262673,0.000494078,9

where the last column will be the name of file without ceros and without extention..only the numbers.

Thanks again for your help Smilie
# 10  
Old 12-03-2013
I leave this as an exercise to you. The FILENAME variable has each respective file's name; you could sub/gsub the extension and/or the zeroes, and append the result like the other fields.
This User Gave Thanks to RudiC For This Post:
# 11  
Old 12-03-2013
Smilie Thanks I will try..

---------- Post updated at 09:48 AM ---------- Previous update was at 09:25 AM ----------


Dear RudiC,

I have changed
Code:
*.txt

instead of
Code:
 file

in the script and I got error
Code:
No such file or directory?..

Smilie

---------- Post updated at 10:23 AM ---------- Previous update was at 09:48 AM ----------

Dear RudiC.
there was a problem with my file... apologies it works fine now

Last edited by jiam912; 12-03-2013 at 11:32 AM..
# 12  
Old 12-03-2013
If you're happy with your code, why don't you post it as the solution to your first request?
These 2 Users Gave Thanks to RudiC For This Post:
# 13  
Old 12-03-2013
Dear RudiC

Here the last modification that I did to the script it works fine
Code:
#!/bin/bash 

rm -f *.csv*

awk -F, 'FNR<18 || $1!~/[RS]/ {next}
                                {gsub (/_/,",")}
         FNR==18                {A=$2;B=$3}
                                {C=FILENAME}
                                {$(NF+1)=A
                                 $(NF+1)=B
                             $(NF+1)=C
                 {gsub (/.adsta/,"")}
                                 print > $1"P.csv"} 
    ' OFS="," *.adsta

Thanks a lot for your support
# 14  
Old 12-04-2013
Thanks for posting your solution. May I propose a few minor modifications?
Code:
awk -F, 'FNR<18 || $1!~/[RS]/ {next}
                                {gsub (/_/,",")}
         FNR==18                {A=$2;B=$3}
                                {C=FILENAME}             # Needless to do this for every line
                                {$(NF+1)=A
                                 $(NF+1)=B
                             $(NF+1)=C
                 {gsub (/.adsta/,"")}                    # Needless to do this for every line; curly braces also pointless
                                 print > $1"P.csv"} 
    ' OFS="," *.adsta

So it might look like
Code:
awk -F, 'FNR<18 || $1!~/[RS]/   {next}
                                {gsub (/_/,",")}
         FNR==18                {A=$2;B=$3 
                                 C=FILENAME 
                                 gsub (/.adsta/,"",C)}       # up to here done once for line no. 18
                                {$(NF+1)=A
                                 $(NF+1)=B
                                 $(NF+1)=C
                                 print > $1"P.csv"}
    ' OFS="," *.adsta

This User Gave Thanks to RudiC For This Post:
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