can Awk split my field on the .


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting can Awk split my field on the .
# 1  
Old 10-26-2007
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 8888.1 99999 path
A 2007/10/20 09:55:00 li text fa57.2a4b8 name 7777.1 99998 path

What i need to do is output a command line for each entry like:

request -p ef6da -m li -v 99999 path
request -p fa57 -m li -v 99998 path

What I am having problems with is splitting the first part of the 6th field, I need the portion prior to the period and not the part after. My attempt has stymied at:

cat filename | awk '{printf "request -p %s -m li -v %s path", $6, $9}' > outfile

I have been trying to modify the field within this format and can't get it to work. MY BRAIN IS FRIED

ANY help would be appreciated. Running on solaris 9 so I have awk, sed, & perl available.
# 2  
Old 10-26-2007
awk has a split() function split(value, array, separator)
In your case:
Code:
split($6, myarray, ".")

myarray now has two elements - the first and second subfields of the sixth field.
# 3  
Old 10-26-2007
Code:
awk '$0="request -p "$6" -m li -v" $11" path"' FS="[ .]" filename

Use nawk or /usr/xpg4/bin/awk on Solaris.
# 4  
Old 10-26-2007
Quote:
Originally Posted by jim mcnamara
awk has a split() function split(value, array, separator)
In your case:
Code:
split($6, myarray, ".")

myarray now has two elements - the first and second subfields of the sixth field.
This returns the size of the array, how do i access the value of a[0]

---

Code:
awk '$0="request -p "$6" -m li -v" $11" path"' FS="[ .]" filename

This doesn't work on my system at all it errors. The FS option doesn't say what it is affecting does that mean it should work on all entries. Also aren't there supposed to be braces ({}) around the awk script. what is the $0 supposed to give me, it looks like it is creating a string variable. Am i supposed to put this in the place of the awk string I showed originally?
# 5  
Old 10-26-2007
Quote:
Originally Posted by radoulov
Code:
awk '$0="request -p "$6" -m li -v" $11" path"' FS="[ .]" filename

Use nawk or /usr/xpg4/bin/awk on Solaris.
Code:
awk '{ printf("request -p %s -m -li -v %s %s\n", $6, $11, $12) }' FS="[ .]" filename

# 6  
Old 10-26-2007
Quote:
Originally Posted by oly_r
This returns the size of the array, how do i access the value of a[0]

---

Code:
awk '$0="request -p "$6" -m li -v" $11" path"' FS="[ .]" filename

This doesn't work on my system at all it errors. The FS option doesn't say what it is affecting does that mean it should work on all entries. Also aren't there supposed to be braces ({}) around the awk script. what is the $0 supposed to give me, it looks like it is creating a string variable. Am i supposed to put this in the place of the awk string I showed originally?
It works as expected with GNU Awk, nawk and POSIX (xpg) awk.
Coud you post the error message(s)?
This User Gave Thanks to radoulov For This Post:
# 7  
Old 10-26-2007
Quote:
Originally Posted by vgersh99
Code:
awk '{ printf("request -p %s -m -li -v %s %s\n", $6, $11, $12) }' FS="[ .]" filename

My mistake,
I didn't realize that "path" was part of the record.

Last edited by radoulov; 10-26-2007 at 09:22 PM..
This User Gave Thanks to radoulov For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. Shell Programming and Scripting

How to split file into multiple files using awk based on 1 field in the file?

Good day all I need some helps, say that I have data like below, each field separated by a tab DATE NAME ADDRESS 15/7/2012 LX a.b.c 15/7/2012 LX1 a.b.c 16/7/2012 AB a.b.c 16/7/2012 AB2 a.b.c 15/7/2012 LX2 a.b.c... (2 Replies)
Discussion started by: alexyyw
2 Replies

5. 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

6. 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

7. 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

8. Shell Programming and Scripting

awk script to split field data

Hi Experts, I have a Input.txt document which contains data fields seperated by tabs. There are 4 fields totally Named UNIQUE, ORDER, CONTACT and WINS. The UNIQUE field contains unique ID and the CONTACT field contains data seperated by comma in some records. I am looking to write an awk script... (12 Replies)
Discussion started by: forumthreads
12 Replies

9. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies

10. 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
Login or Register to Ask a Question