split the file based on the 2nd column passing as a parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting split the file based on the 2nd column passing as a parameter
# 8  
Old 07-16-2010
MySQL awk: 0602-590 Internal software error in the tostring function on 1

This is the one exactly i am looking for, I have tried with the small source file. it is working file.
but it is failing for another file due the below error message.Did the awk command does not work for bigger size files.
My oprating system is AIX

Error information:
Code:
awk: 0602-590 Internal software error in the tostring function on 1,Customer Extension Detail,111_222222222,222222226 333333333333333 ,ABC ,BBC ,2000-01-01,2001-01-01,,,,,,,,,,ABCDSED,ASJKSDF,,,,,.
The input line number is 6.73808e+06. The file is /input/source/file/AAAAABBB_200101_1111.csv.
The source line number is 1.

Script information:
Code:
SID=1111
PID=200101
T1=`echo $TargetDir"/"`
 
awk -v var1=$PID -v var2=$SID -v var3=$T1 'BEGIN{FS=OFS=","}{S=$0;gsub(/"/,"");gsub(/ /,"_",$2)} /Detail/ {print S> var3$2"_"var1"_"var2".txt"}' filename.csv

Thanks

---------- Post updated at 11:30 PM ---------- Previous update was at 05:57 AM ----------

Additional information,
I have guessed the below possibilities and cross verified.

1. Data issue
Cross checked the source data is having correct format. No issues with the source data.
Tried to extract with grep for the particular string. i am able to fetch the data. No data issues.

2. Awk command
The below command need to change the syntax to execute for the bigger files.
The below command is working fine with the small files <1GB. Not working more then 1GB file.
I don't know where the awk execute in the server side - May be environment issue.
I am unable to tune the below awk command.
I have cross checked in the forams, i did not find the similar issue/error.

Finally, i have tried all the possibilities like source data, environmental issues (Hardware resource -CPU,Buffer)- every thing looks fine.
But still i am facing this issue. I am unable to figure out where is the problem to execute the below command

Thanks


---------- Post updated 07-15-10 at 03:49 AM ---------- Previous update was 07-14-10 at 11:30 PM ----------

Hi,
I am going to chnage the script


Code:
PID=20001010
SID=1200
var1=`echo $file"Detail"` #var1=customer_relation_information_Detail
var2=`echo $var1| awk '{gsub(/_/, " ");print}'` #var2=customer relation information Detail
echo $var2 #customer relation information Detail
 
awk '/$var2/' $InputDir/$file1 > `echo $TempDir/$file"Detail_"$PID"_"$SID".txt"`
#---------------------------------OR-------------------------------------------
awk -v temp=$var2 '/$temp/' $InputDir/$file1 > `echo $TempDir/$file"Detail_"$PID"_"$SID".txt"`
#---------------------------------OR-------------------------------------------
awk -v temp1='$var2' '/$temp1/' $InputDir/$file1 > `echo $TempDir/$file"Detail_"$PID"_"$SID".txt"`

The above three awk commands not taking the parameter even i have defind the pameter it is not fetching the data.

Thanks

---------- Post updated 07-16-10 at 12:18 AM ---------- Previous update was 07-15-10 at 03:49 AM ----------

Hi,

Now the 2nd command is working for fine.

Thanks for sharing the command.

Code:
awk -v var1=20001010 -v var2=1000 -v var3=/abc/bbc/file/ -F, '/Detail/ {d=$2;gsub(/\"/,"",d);c=d;gsub(/ /,"_",c);print > var3"/"c"_"var1"_"var2".txt"}' file_name

Now this is resolved.

I dont know how close the thread.
Thanks

Last edited by Scott; 07-16-2010 at 07:06 AM.. Reason: Code tags, PLEASE!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To Split the file based on column value

Hi Team, I have a requirement in such a way that need to split the file into two based on which column particular value appears.Please find my sample file below. Lets consider the delimiter of this file as either comma or two colons.(:: and ,). So I need to split the file in such a way that all... (2 Replies)
Discussion started by: ginrkf
2 Replies

2. Shell Programming and Scripting

Split file based on a column/field value

Hi All, I have a requirement to split file into 2 sets of file. Below is a sample data of the file AU;PTN;24EX;25-AUG-14;AU;123;SE;123;Test NN;;;;ASD; AU;PTN;24EX;25-AUG-14;AU;456;SE;456;Test NN;;;;ASD; AU;PTN;24EX;25-AUG-14;AU;147;SE;147;Test NN;;;;ASD;... (6 Replies)
Discussion started by: galaxy_rocky
6 Replies

3. UNIX for Dummies Questions & Answers

Split file based on column

i have file1.txt asdas|csada|130310|0423|A1|canberra sdasd|sfdsf|130426|2328|A1|sydney Expected output : on eaceh third and fourth colum, split into each two characters asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney (10 Replies)
Discussion started by: radius
10 Replies

4. Shell Programming and Scripting

Split the file based on column

Hi, I have a file sample_1.txt (300k rows) which has data like below: * Also each record is around 64k bytes 11|1|abc|102553|125589|64k bytes of data 10|2|def|123452|123356|...... 13|2|geh|144351|121123|... 25|4|fgh|165250|118890|.. 14|1|abc|186149|116657|......... (6 Replies)
Discussion started by: sol_nov
6 Replies

5. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

6. Shell Programming and Scripting

Split a file into multiple files based on line numbers and first column value

Hi All I have one query,say i have a requirement like the below code should be move to diffent files whose maximum lines can be of 10 lines.Say in the below example,it consist of 14 lines. This should be moved logically using the data in the fisrt coloumn to file1 and file 2.The data of first... (2 Replies)
Discussion started by: sarav.shan
2 Replies

7. Shell Programming and Scripting

How to split a fixed width text file into several ones based on a column value?

Hi, I have a fixed width text file without any header row. One of the columns contains a date in YYYYMMDD format. If the original file contains 3 dates, I want my shell script to split the file into 3 small files with data for each date. I am a newbie and need help doing this. (14 Replies)
Discussion started by: bhanja_trinanja
14 Replies

8. Shell Programming and Scripting

Split into columns based on the parameter and use & as delimiter

Here is my source, i have million lines like this on a file. disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=& drc=&mo=&sid=&lang=EN&loc=JPN I want to split this into columns in order to load in database, anything starts with"&mjv=6" as first... (13 Replies)
Discussion started by: elamurugu
13 Replies

9. Shell Programming and Scripting

Split large file based on last digit from a column

Hello, What's the best way to split a large into multiple files based on the last digit in the first column. input file: f 2738483300000x0y03772748378831x1y13478378358383x2y23743878383802x3y33787828282820x4y43748838383881x5y5 Desired Output: f0 3738483300000x0y03787828282820x4y4 f1... (9 Replies)
Discussion started by: alain.kazan
9 Replies

10. Shell Programming and Scripting

Split single file into multiple files based on the number in the column

Dear All, I would like to split a file of the following format into multiple files based on the number in the 6th column (numbers 1, 2, 3...): ATOM 1 N GLY A 1 -3.198 27.537 -5.958 1.00 0.00 N ATOM 2 CA GLY A 1 -2.199 28.399 -6.617 1.00 0.00 ... (3 Replies)
Discussion started by: tomasl
3 Replies
Login or Register to Ask a Question