Sponsored Content
Full Discussion: Help needed with AWK fields
Top Forums UNIX for Dummies Questions & Answers Help needed with AWK fields Post 302460636 by wthomas on Thursday 7th of October 2010 07:40:49 AM
Old 10-07-2010
Help needed with AWK fields

Hi all,

I currently use the following command to extract the 4th and 9th fields in our Syslog file.

Code:
$ tail messages|awk '{print $4 " " " " $9}'
solsw137-b02b.nls.jlrint.com  %LINK-3-UPDOWN:
hajap105-0106.nls.jlrint.com  %DOT11-6-ASSOC:
hajap101-0103.nls.jlrint.com  %DOT11-6-ROAMED:
hajap101-0103.nls.jlrint.com  %DOT11-6-DISASSOC:
whjap107-0606.nls.jlrint.com  %DOT11-6-ROAMED:
whjap107-0606.nls.jlrint.com  %DOT11-6-DISASSOC:
whjap114-0703.nls.jlrint.com  %DOT11-6-ASSOC:
whjap114-0703.nls.jlrint.com  %DOT11-6-ROGUE_AP:
whjap114-0703.nls.jlrint.com  %DOT11-6-ROGUE_AP:
solsw137-b02b.nls.jlrint.com  %RTD-1-LINK_FLAP:

I want to also include all fields in the actual messages starting with the 10th field.
I could do for example; tail messages|awk '{print $4 " " " " $9, $10, $11, $12, $13}'

In the above command, there are many more fields after the 13th field, but rather than inputting all fields, for which I have no idea how many fields there could be. I would rather use an expression (if there is one) that would simply include all fields from field 9 onwards to the end of the message.

Could you please help me out here.

Regards, Wynford

Last edited by vbe; 10-08-2010 at 05:50 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Awk - more than 99 fields?

Just written a great little script that analyses a flat ASCII CSV file and reports for any discrepancies with field counts per record etc. Works fine on all the flat files except one, which has 113 fields per line. AWK can only seemingly cope with up to 99 fields. Is there any way around... (2 Replies)
Discussion started by: DaveM
2 Replies

2. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

3. Shell Programming and Scripting

awk 2 fields duplicate and 1 different

I have file that I need to remove the duplicates. The problem is, I need to only keep the one which has a unique 3rd field. Here is a sample file: xxx.xxx:x:CISCO1.CLEVE61W:ERIE.NET:x:x:x:x: xxx.xxx:x:CISCO2.CLEVE62W:OHIO.NET:x:x:x:x: xxx.xxx:x:CISCO2.CLEVE62W:NORTH.NET:x:x:x:x:... (1 Reply)
Discussion started by: numele
1 Replies

4. Shell Programming and Scripting

Awk; gsub in fields 3 and 4

I want to transform a log file into input for a database. Here's the log file: Tue Aug 4 20:17:01 PDT 2009 Wireless users: 339 Daily Average: 48.4285 = Tue Aug 11 20:17:01 PDT 2009 Wireless users: 295 Daily Average: 42.1428 = Tue Aug 18 20:17:01 PDT 2009 Wireless users: 294 Daily... (6 Replies)
Discussion started by: Bubnoff
6 Replies

5. UNIX for Dummies Questions & Answers

fields in AWK

I feel like a real leech now, 3 questions in 3 days, but hopefully when I get my head around all of this I can contribute back to this community! Anyway, so a couple of you guys have gotten me onto AWK and I've been researching it a little over the last couple of hours, now I'm somewhat sure I... (2 Replies)
Discussion started by: Aussiemick
2 Replies

6. Shell Programming and Scripting

No. of Fields using Awk

Hi, Could someone please let me know me how i can use an awk command to print the No. of fields of each file present in a Directory?Suppose the Directory has 5 text files in which the first record in each file contains fields separated by a '|'. I need to use a awk command to display the No... (8 Replies)
Discussion started by: pchegoor
8 Replies

7. Shell Programming and Scripting

Join fields comparing 4 fields using awk

Hi All, I am looking for an awk script to do the following Join the fields together only if the first 4 fields are same. Can it be done with join function in awk?? a,b,c,d,8,,, a,b,c,d,,7,, a,b,c,d,,,9, a,b,p,e,8,,, a.b,p,e,,9,, a,b,p,z,,,,9 a,b,p,z,,8,, desired output: ... (1 Reply)
Discussion started by: aksijain
1 Replies

8. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

9. Shell Programming and Scripting

awk - compare 1st 15 fields of record with 20 fields

I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies

10. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies
iconv(1)						      General Commands Manual							  iconv(1)

NAME
iconv - Converts encoded characters to another codeset SYNOPSIS
iconv -f from_code -t to_code [file...] STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: iconv: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
Specifies the input codeset. Specifies the output codeset. OPERANDS
Specifies one or more files that contain the data to be converted. If this operand is omitted, the standard input is used. DESCRIPTION
The iconv command converts the encoding of characters in file from one coded character set to another and writes the results to standard output. The input and output coded character sets are identified by from_code and to_code. If the file operand is not specified on the command line, the iconv command reads the standard input. The result of specifying invalid characters in the input stream is that the input value is translated to the substitute character. [Tru64 UNIX] Current industry standards do not specify the name format, implementation, and location of the codeset converters used by this command. On this operating system, the command searches directories of algorithmic and table converters to find one that performs the requested conversion. The names of codeset converters adhere to the following format: fromcode_tocode EXIT STATUS
Success. An error occurred. ERRORS
[Tru64 UNIX] You can view the diagnostic messages that may be returned by the iconv command by entering the following commands: cd /usr/lib/nls/msg/en_US.ISO8859-1 dspcat iconv.cat EXAMPLES
The following examples use the iconv command: To convert the contents of the eucJP_data file from the eucJP to the SJIS codeset and save the results in the sjis_data file, enter: iconv -f eucJP -t SJIS eucJP_data > sjis_data To convert the contents of the eucJP_data file from the eucJP codeset to the UCS-4 codeset and save the results in the UCS_4_data file, enter: iconv -f eucJP -t UCS-4 eucJP_data > UCS_4_data ENVIRONMENT VARIABLES
The following environment variables (see i18n_intro(5) and l10n_intro(5)) affect the execution of the iconv command: Specifies a default value for the locale category variables that are not set. If set to a nonempty string value, overrides the values of all other locale variables, including LANG. Determines the locale for interpreting byte sequences as characters in, for example, command parameters. Spec- ifies the locale used to find translations, if any, for the command's message catalogs. [Tru64 UNIX] Specifies the search path used to find locales and the subdirectories that contain codeset converters. The default is /usr/lib/nls/loc. Determines the location of message catalogs for the processing of LC_MESSAGES. FILES
[Tru64 UNIX] Algorithmic converters. [Tru64 UNIX] Table converters. SEE ALSO
Commands: genxlt(1) Functions: iconv(3), iconv_close(3), iconv_open(3) Others: i18n_intro(5), iconv_intro(5), l10n_intro(5), standards(5) Writing Software for the International Market iconv(1)
All times are GMT -4. The time now is 01:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy