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.

awk has a split() function split(value, array, separator)
In your case:

split($6, myarray, ".")

myarray now has two elements - the first and second subfields of the sixth field.

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

Use nawk or /usr/xpg4/bin/awk on Solaris.

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?

awk '{ printf("request -p %s -m -li -v %s %s\n", $6, $11, $12) }' FS="[ .]" filename

It works as expected with GNU Awk, nawk and POSIX (xpg) awk.
Coud you post the error message(s)?

1 Like

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

1 Like