how to give multiple csv files as input in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to give multiple csv files as input in awk
# 1  
Old 11-16-2010
MySQL how to give multiple csv files as input in awk

Hi All,
I am new to shell scripting..My problem is i want to give multiple csv files as input to awk script and process the data into one file..

My input file is

File1 File2 File3
Code:
Product Location  Period        SalesPrice
A x                  8/11/2010       445
B y                  9/11/2010       445
C z                  so on             445
D a                  so on              445

The output should contain all these files together in one file..

Please help me!!

Last edited by radoulov; 11-16-2010 at 04:11 AM.. Reason: the columns were merged; Added code tags.
# 2  
Old 11-16-2010
Code:
paste file1 file2 ...

# 3  
Old 11-16-2010
But it is not working.. presently i m using this code..
Code:
#!/bin/sh
AWKPAT='BEGIN{
FS=OFS=","
FILENAME=="'$1'"
while(i<1000)
        {
   FcstQty = int(rand()*100);
   rnd[FcstQty]++;
   i++;
      }
 
  print "ProductId     ShipFromLoc     Period       SalesPrice    FcstAmt\n"
  }
  {
  print $1"     "$2"      "$3 "       "$4 "        " $4*FcstQty
   }'
   awk "$AWKPAT" $1

but here i use one csv file as input.. instead i want to use 3 csv files as input.

please help me

Last edited by radoulov; 11-16-2010 at 04:23 AM.. Reason: Please use code tags.
# 4  
Old 11-16-2010
Could you kindly elaborate further on "it is not working"?
It would be definitely easier if you post some sample data
and an example of the desired output
(just please post the content of the distinct input files separately) .
# 5  
Old 11-16-2010
Thanks for your reply...
My problem is..
I have three csv files, File1,File2,File3
The file1 has ProductId and Location of Quantities.
File2 has Periods(i.e. the date)
File3 has SalesPrice of each quantity..

I have to display all these in one file
My desired output:

Code:
ProductId ShipFromLoc Period             SalesPrice        FcstAmt
CH-SM-TW-01 Bangalore 2010-08-06     475               47025
CH-SM-RW-02 Chennai 2010-08-13         475              47025
CH-BG-RW-03 Pune 2010-08-20             475               47025
CH-BG-TW-04 Mumbai 2010-08-27         475               47025


Last edited by radoulov; 11-16-2010 at 05:00 AM.. Reason: Please use code tags!
# 6  
Old 11-16-2010
OK,
please post samples with the exact format of file1, file2 and file3.
And use code tags, please!
# 7  
Old 11-16-2010
File1:
Code:
ProductId        Location
CH-SM-TW-01  Bangalore
Ch-SM-RW-02  Chennai
Ch-Bg-RW-03    Pune
Ch-Bg-Tw-04   Mumbai


File2
Code:
Period
8/11/2010
7/11/2010
3/11/2010
5/11/2010

File3
Code:
SalesPrice
445
334
554
445..

These are the sample input files

---------- Post updated at 04:14 AM ---------- Previous update was at 04:06 AM ----------

i use cygwin for executing and awk scripting..i want to display the output on the cygwin command prompt...

---------- Post updated at 04:14 AM ---------- Previous update was at 04:14 AM ----------

i use cygwin for executing and awk scripting..i want to display the output on the cygwin command prompt...

Last edited by Franklin52; 11-16-2010 at 05:33 AM.. Reason: Please use code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Export Oracle multiple tables to multiple csv files using UNIX shell scripting

Hello All, just wanted to export multiple tables from oracle sql using unix shell script to csv file and the below code is exporting only the first table. Can you please suggest why? or any better idea? export FILE="/abc/autom/file/geo_JOB.csv" Export= `sqlplus -s dev01/password@dEV3... (16 Replies)
Discussion started by: Hope
16 Replies

2. UNIX for Dummies Questions & Answers

Multiple string input in a awk

Hi everybody, I just start my learning about Linux. So, if you can help me, it would be very good ! I have already find the possibility to find the position of a character regular expression in a line with the help of awk : test.txt is : AAAAAGHIJKLAjKMEFJKLjklABCDJkLEFGHIJKL My script is... (2 Replies)
Discussion started by: thewizarde6
2 Replies

3. Shell Programming and Scripting

[Solved] Multiple input files and output files

Hi, I have many test*.ft1 files to which I want to read as input for a script called pipe2txt.tcl and print the output in each separate file. For example, pipe2txt.tcl < test001.ft1 > test001.txt How can I read many files in this maner? thank you very much, Best, Pahuja (5 Replies)
Discussion started by: Pahuja
5 Replies

4. Shell Programming and Scripting

FOR loop with multiple files as input and awk

Hi all , i want to pass multiple files as input to a for loop for i in file1 file2 file3 do some awk action < $i >> $i.out done but im getting error in that for loop is the way i use to pass files to awk using for correct and 2.we can directly pass multiple files to awk as... (7 Replies)
Discussion started by: zozoo
7 Replies

5. Shell Programming and Scripting

Splitting input CSV file into 3 files

Hi , I am receiving a CSV file that can vary in number of rows each time. I am supposed to split this file into 3 separate files like this: 1. create a file named 'File1.csv' that will contain first 3 rows of the input file 2. create file named 'File2.csv' that will contain last 3 rows of the... (7 Replies)
Discussion started by: kedrick
7 Replies

6. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

7. Shell Programming and Scripting

How to generate a csv files by separating the values from the input file based on position?

Hi All, I need help for doing the following. I have a input file like: aaaaaaaaaabbbbbbbbbbbbbbbbbbbb cccbbbbbaaaaaadddddaaaabbbbbbb now I am trying to generate a output csv file where i will have for e.g. 0-3 chars of each line as the first column in the csv, 4-10 chars of the line as... (3 Replies)
Discussion started by: babom
3 Replies

8. Shell Programming and Scripting

awk, multiple files input and multiple files output

Hi! I'm new in awk and I need some help. I have a folder with a lot of files and I need that awk do something in each file and print a new file with the output. The input file name should be modified when I print the outpu files. Thanks in advance for help! :-) ciao (5 Replies)
Discussion started by: gabrysfe
5 Replies

9. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

10. Shell Programming and Scripting

Splitting input files into multiple files through AWK command

Hi, I needs to split *.txt files from single directory depends on the some mutltiple input values. i have wrote the code like below for file in *.txt do grep -i -h "value1|value2" $file > $file; done. My requirment is more input values needs to be given in grep; let us say 50... (3 Replies)
Discussion started by: arund_01
3 Replies
Login or Register to Ask a Question