Sponsored Content
Top Forums Shell Programming and Scripting awk script to split field data Post 302337034 by forumthreads on Thursday 23rd of July 2009 09:15:43 AM
Old 07-23-2009
Quote:
Originally Posted by Ygor
Code:
$ awk '{n=split($3,arr,",");for(i=0;i++< n;){printf "%s\t%s\n",$1,arr[i];}}/#/' file1
UNIQUE  CONTACT
G001    Swr
G002    B
G002    DR
G002    P
G003    A
G004    PO
G004    A

With FS set to tab..
Code:
$ awk -F '\t' '{n=split($3,arr,",");for(i=0;i++< n;){printf "%s\t%s\n",$1,arr[i];}}/#/' file1
UNIQUE  CONTACT
G001    Swr Pq
G001    SD
G002    B
G002    DR
G002    P
G003    A F
G004    PO
G004    A C

Ygor,
I tried this code and get the following message, I have typed exactly as shown by you.
awk: syntax error near line 1
awk: bailing out near line 1
Any idea what i am doing wrong

Many Thanks for all your responses.

---------- Post updated at 02:15 PM ---------- Previous update was at 02:13 PM ----------

Quote:
Originally Posted by Franklin52
Have you tried the solution of Ygor?
Franklin,

Yes i did try Ygor solution (with tab) but get syntax error, any idea what could go wrong?

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split a field in awk script

Hi all, I have a field in the line, let's say argument $6, which is in the format 00.00 If i want to split the field to get rid of the "." in between of the amount, how can i do that i awk script? I have it like this split($6,a,".") but it will get rid of the last 2 digits after the... (4 Replies)
Discussion started by: CamTu
4 Replies

2. Shell Programming and Scripting

can Awk split my field on the .

I am trying to pull data out of a file to execute a series of repetitive commands. One of the fields is a {hex number}.{hex number} pattern. I need the first part of that structure to pass into the command. The file structure is like this: A 2007/10/20 09:50:00 li text ef6da.1 name ... (6 Replies)
Discussion started by: oly_r
6 Replies

3. Shell Programming and Scripting

simple awk question: split field with :

Hi, Probably a very weak question.. but I have tried all I know.. BPC0001:ANNUL_49542 0.0108 -0.0226 -0.0236 0.0042 0.0033 -0.0545 0.0376 0.0097 -0.0093 -0.032 Control BPC0002:ANNUL_49606 0.0190 -0.0142 -0.0060 -0.0217 -0.0027 ... (3 Replies)
Discussion started by: genehunter
3 Replies

4. Shell Programming and Scripting

Split field with awk

Hi there I have a text file with several fields separated by ";" as follow : 5466-43;5466;JOAN;LIGA;LIGA ESPANOLA;43;DEP LA CORUNA - OSASUNA;10/01/10 17:00 5466-44;5466;CARLES;LIGA;LIGA ESPANOLA;44;MALAGA - ATHL BILBAO;10/01/10 17:00 5466-45;5466;FAB;LIGA;LIGA ESPANOLA;45;REAL MADRID -... (4 Replies)
Discussion started by: capnino
4 Replies

5. Shell Programming and Scripting

Split File data using awk

HI Guys, I need to split the file in to number of files . file contains FILEHEADER and EOF . I have to split n number of times . I have to form the file with each splitted message between FILEHEADER and EOF using awk beign and end . how to implement please suggest. (2 Replies)
Discussion started by: manish8484
2 Replies

6. Shell Programming and Scripting

awk to split one field and print the last two fields within the split part.

Hello; I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
Discussion started by: yifangt
5 Replies

7. Shell Programming and Scripting

AWK script to split data and find average

Input: 2.58359023380340e+02 1.43758864405595e+02 -7.65700666212508e+00 1.06460208083228e+02 1.26185441783936e+02 -3.41389169427027e+01 -1.40393299309592e+02 -3.07758776849508e+01 1.45067703495838e+02 1.79405834959073e+02 5.06666234594205e+01 OUT 2.0105894389e+02 (average of... (8 Replies)
Discussion started by: chrisjorg
8 Replies

8. Shell Programming and Scripting

awk split after second underscore in field

I am trying to split a tab-delimeted file using awk after the second _ in bold. The awk below is close but splits on the first _, and I am not sure how to use the second _. Thank you :). file chr1 92145889 92149424 NM_001195684_exon_0_10_chr1_92145900_r 0 - chr1 92161218 ... (4 Replies)
Discussion started by: cmccabe
4 Replies

9. Shell Programming and Scripting

awk to add plus or minus to fields and split another field

In the tab-delimited input below I am trying to use awk to -10 from $2 and +10 to $3. Something like awk -F'\t' -v OFS='\t' -v s=10 '{split($4,a,":"); print $1,$2-s,$3+s,a,$5,$6} | awk {split(a,b,"-"); print $1,$2-s,$3+s,b-s,b+s,$5,$6}' input should do that. I also need to -10 from $4... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. UNIX for Beginners Questions & Answers

awk to split field twice using two deliminators

In the awk I am splitting on the : into array a, then splitting on the - into element b. I can not seem to duplicate b if there is no - after it. Lines 1,2,4 are examples. If there is a - after the number in b then the value to the right of it is $3 in the ouput. Thank you :). awk... (2 Replies)
Discussion started by: cmccabe
2 Replies
LOCALE_PARSE(3) 							 1							   LOCALE_PARSE(3)

Locale::parseLocale - Returns a key-value array of locale ID subtag elements.

	Object oriented style

SYNOPSIS
publicstatic array Locale::parseLocale (string $locale) DESCRIPTION
Procedural style array locale_parse (string $locale) Returns a key-value array of locale ID subtag elements. PARAMETERS
o $locale - The locale to extract the subtag array from. Note: The 'variant' and 'private' subtags can take maximum 15 values whereas 'ext- lang' can take maximum 3 values. RETURN VALUES
Returns an array containing a list of key-value pairs, where the keys identify the particular locale ID subtags, and the values are the associated subtag values. The array will be ordered as the locale id subtags e.g. in the locale id if variants are '-varX-varY-varZ' then the returned array will have variant0=>varX , variant1=>varY , variant2=>varZ EXAMPLES
Example #1 locale_parse(3) example <?php $arr = locale_parse('sl-Latn-IT-nedis'); if ($arr) { foreach ($arr as $key => $value) { echo "$key : $value , "; } } ?> Example #2 OO example <?php $arr = Locale::parseLocale('sl-Latn-IT-nedis'); if ($arr) { foreach ($arr as $key => $value) { echo "$key : $value , "; } } ?> The above example will output: language : sl , script : Latn , region : IT , variant0 : NEDIS , SEE ALSO
locale_compose(3). PHP Documentation Group LOCALE_PARSE(3)
All times are GMT -4. The time now is 10:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy