If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > AWK: Removing Characters from field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-04-04, 17:58
davioli davioli is offline
Registered User
 
Join Date: Jul 2004
Posts: 4
Unhappy AWK: Removing Characters from field

Hello,

When I use AWK I seem to have a problem with the newline character attaching itself to the last field I request. I use AWK to gather fields from a line in a log file. When I ask AWK to grab the last field, it takes the number plus the newline character at the end of the line. I would like to know of anyway of making AWK ignore the newline character when gathering field values. The reason I want to drop the newline character is that I want to add the string $MSU (passed by shell script) to the end of the line without this error occuring.

------------------------------------------------------------
#!/bin/sh
fieldNum=$1
/usr/bin/awk -v field=$fieldNum 'BEGIN{numOfFields=split(field,fieldList,",")} {
for ( x = 2 ; x < NF ; x += 2 )
fields[$x] = sprintf("%s",$(x+1));
for ( i=1;i<=numOfFields;i++ ) {
if ( fields[fieldList[i]] != "" )
printf fields[fieldList[i]] " " ;
}
print "'"$MSU"'";
}
'

---------------------------------------------------------
Any help on the matter would be greatly appreciated.
_David
Reply With Quote
  #2 (permalink)  
Old 08-05-04, 12:27
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
I don't believe this is the case. A newline character is the default record separator in awk and would not be read in as part of the line.

It's more likely the problem is down to the data you are running your script against.

Can you post some sample data that would illustrate what you mean? The value of $1 you are passing to your script would also be useful.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On