Record splitting with AWK


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Record splitting with AWK
# 1  
Old 10-23-2008
Record splitting with AWK

Hi all !

I need your help as quick as possible.

My input file like this:

bạc těnh ( 薄情) 1 . 薄情な.2. 夫婦或いは男女の不貞を指す。
bách (百,迫)1.100ドソ. tr a m b a c ともいう. 2.柏(カヽしわ)・ 3.圧迫する.4.差し迫った,

My propose is take the value in the firt bracket. I used the command like :
...if (index( $3,"(")==1)$3=substr($3,2,index($3,")")-1);
else if (index( $3,"(")==1)$3=substr($3,2,index($3,")1."-3);
and my result with the fist line, i take the value 薄情.
but the second line, the value is wrong. Because it took 百,迫)1.100ドソ. tr a m b a c ともいう. 2.柏(カヽしわ.
but I want to take the 百,迫.

So what can I do?
# 2  
Old 10-23-2008
Try this:

Code:
awk -F'[)(]' '{print $2}' infile

Note:

Moved to Q & A.
To the OP: please don't post to unrelated old threads, open a new one instead.
Thank you!

Last edited by radoulov; 10-23-2008 at 04:58 AM..
# 3  
Old 10-23-2008
Thanks you so much!

But I did not know what does this mean of funtion -F
# 4  
Old 10-23-2008
Try this, I have used ( or ) as fieldseparators:

Code:
awk 'BEGIN{FS="\(|\)"} {print $2}' file

Regards
# 5  
Old 10-23-2008
Thanks!

Before, I do like this:
BEGIN {
FS="\t";RS="\n";
}
Because now I want to take the words during ( ), and $3 it means the value I will take.
I write like this
if (index( $3,"(")==0 && index($3,"・・)==0)$3="";
else if (index( $3,"(")==1)$3=substr($3,2,index($3,"・・)-2);

My result will have 2 column, 1 is
bách
and the second column is 百,迫
but now I have problem when the lines have 2 ( ) like this
bách (百,迫)1.100ドソ. tr a m b a c ともいう. 2.柏(カヽしわ)

After the bách I use tab code(button) and before the bách I also using the tab code.

And my result is
bách 百,迫)1.100ドソ. tr a m b a c ともいう. 2.柏(カヽしわ

Then could you help me to fix my mistake?
# 6  
Old 10-23-2008
The problem is that the file is not well structured, you can try:

Code:
awk -F'[)(]' '{print $1, $2}' infile

Regards
# 7  
Old 10-23-2008
Quote:
Originally Posted by maixu134
Before, I do like this:
BEGIN {
FS="\t";RS="\n";
}
Because now I want to take the words during ( ), and $3 it means the value I will take.
I write like this
if (index( $3,"(")==0 && index($3,"・・)==0)$3="";
else if (index( $3,"(")==1)$3=substr($3,2,index($3,"・・)-2);

My result will have 2 column, 1 is
bách
and the second column is 百,迫
but now I have problem when the lines have 2 ( ) like this
bách (百,迫)1.100ドソ. tr a m b a c ともいう. 2.柏(カヽしわ)

After the bách I use tab code(button) and before the bách I also using the tab code.

And my result is
bách 百,迫)1.100ドソ. tr a m b a c ともいう. 2.柏(カヽしわ

Then could you help me to fix my mistake?
OK,
could you please post the output of the command below and explain what's wrong with it?
Just run it in your terminal:

Code:
awk -F'[)(]' '{print $1, $2}' name_of_your_input_file


Last edited by radoulov; 10-23-2008 at 08:53 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Splitting strings

Hi All, There is a file with a data. If the line is longer than 'n', we splitting the line on the parts and print them. Each of the parts is less than or equal 'n'. For example: n = 2; "ABCDEFGHIJK" -> length 11 Results: "AB" "CD" EF" GH" "IJ" "K" Code, but there are some errors.... (9 Replies)
Discussion started by: booyaka
9 Replies

2. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

3. Shell Programming and Scripting

Splitting file using awk

I have file with below content FG1620000|20000 FG1623000|23000 FG1625000|25000 FG1643894|43894 FG1643895|43895 FG1643896|43896 FG1643897|43897 FG1643898|43898 My aim is to split the above file into two files based on the value in the second field. If the value in second field is... (2 Replies)
Discussion started by: anijan
2 Replies

4. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies

5. Shell Programming and Scripting

Need help splitting huge single record file

I was given a data file that I need to split into multiple lines/records based on a key word. The problem is that it is 2.5GB or bigger and everything I try in perl or sed causes a Segmentation fault. Can someone give me some other ideas. The data is of the form:... (5 Replies)
Discussion started by: leolson
5 Replies

6. UNIX for Dummies Questions & Answers

awk, splitting date

can any1 explain me hw is below wrking: wat is substr and dd,mmyear used for wat values will go in dese? sdt='31122010235959' sdate=`validate_date $sdt` validate_date() { dt="$1" set `echo $dt | nawk '{ print... (2 Replies)
Discussion started by: musu
2 Replies

7. Shell Programming and Scripting

Splitting string with awk

Input: Debris Linux is a minimalist, desktop-oriented distribution and live CD based on Ubuntu. It includes the GNOME desktop and a small set of popular desktop applications, such as GNOME Office, Firefox web browser, Pidgin instant messenger, and ufw firewall manager. Debris Linux ships... (5 Replies)
Discussion started by: cola
5 Replies

8. Shell Programming and Scripting

Issue while splitting a row of record

Hi, I have one file with the following details, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Account_Id Date Id Balance 44 9 1000.00 30 15-10-2173 10 1000.00 42 15-10-2173 10 1200.00 53 01-01-2008 10 1200.00 I need to split up the values in to the respective fields as follows, ... (7 Replies)
Discussion started by: Kattoor
7 Replies

9. UNIX for Dummies Questions & Answers

Splitting a file based on record sin another file

All, We receive a file with a large no of records (records can vary) and we have to split it into two files based on another file. e.g. File1: UHDR 2008112 "25187","00000022","00",21-APR-1991,"" ,"D",-000000519,+0000000000,"C", ,+000000000,+000000000,000000000,"2","" ,21-APR-1991... (7 Replies)
Discussion started by: er_ashu
7 Replies

10. Shell Programming and Scripting

splitting a record and adding a record to a file

Hi, I am new to UNIX scripting and woiuld appreicate your help... Input file contains only one (but long) record: aaaaabbbbbcccccddddd..... Desired file: NEW RECORD #new record (hardcoded) added as first record - its length is irrelevant# aaaaa bbbbb ccccc ddddd ... ... ... (1 Reply)
Discussion started by: rsolap
1 Replies
Login or Register to Ask a Question