Help with awk statement to format text file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk statement to format text file.
# 1  
Old 07-17-2013
Help with awk statement to format text file.

Hello,

I am fairly new to shellscripting and have written a script to check on messages file and report failed logins:

Here is the original file:
Code:
Jul 17 03:38:07 sfldmilx086 sshd[30798]: error: PAM: Authentication failure for houghn97 from 10.135.77.201
Jul 17 03:38:07 sfldmilx086 sshd[30798]: error: PAM: Authentication failure for fghdfhfhgdfghdfgh from 10.135.77.201
Jul 17 03:38:07 sfldmilx086 sshd[30798]: error: PAM: Authentication failure for fghdfhfhgdfghdfgh from 10.135.77.201
Jul 17 03:38:08 sfldmilx086 sshd[30798]: error: PAM: Authentication failure for houghn97 from 10.135.77.201
Jul 17 03:38:09 sfldmilx086 sshd[30798]: error: PAM: Authentication failure for houghn97 from 10.135.77.201
Jul 17 03:38:10 sfldmilx086 sshd[30798]: error: PAM: Authentication failure for houghn97 from 10.135.77.201
Jul 17 03:38:11 sfldmilx086 sshd[30798]: error: PAM: Authentication failure for houghn97 from 10.135.77.201
Jul 17 03:38:12 sfldmilx086 sshd[30798]: error: PAM: Authentication failure for houghn97 from 10.135.77.201

I want to reformat that information using awk but sometimes the columns do not line up:

Code:
cat nn|awk '{print $11,"\t",$5,"\t",$1,$2,$3,"\t","("$13")";}'

houghn97         sshd[30798]:    Jul 17 03:38:07         (10.135.77.201)
fghdfhfhgdfghdfgh        sshd[30798]:    Jul 17 03:38:07         (10.135.77.201)
fghdfhfhgdfghdfgh        sshd[30798]:    Jul 17 03:38:07         (10.135.77.201)
houghn97         sshd[30798]:    Jul 17 03:38:08         (10.135.77.201)
houghn97         sshd[30798]:    Jul 17 03:38:09         (10.135.77.201)
houghn97         sshd[30798]:    Jul 17 03:38:10         (10.135.77.201)
houghn97         sshd[30798]:    Jul 17 03:38:11         (10.135.77.201)
houghn97         sshd[30798]:    Jul 17 03:38:12         (10.135.77.201)

Any help greatly appreciated.

Thanks
Neil.

Last edited by DukeNuke2; 07-17-2013 at 08:03 AM..
# 2  
Old 07-17-2013
If you have column command make use of it.
check -t option in
Code:
 
man column

# 3  
Old 07-17-2013
Thank you very much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format the text using sed or awk

I was able to figure out how to format a text. Raw Data: $ cat test Thu Aug 23 15:43:28 UTC 2018, hostname01, 232.02, 3, 0.00 Thu Aug 23 15:43:35 UTC 2018, hostname02, 231.09, 4, 0.31 Thu Aug 23 15:43:37 UTC 2018, hostname03, 241.67, 4, 0.43 (5 Replies)
Discussion started by: kenshinhimura
5 Replies

2. Shell Programming and Scripting

Converting text files to xls through awk script for specific data format

Dear Friends, I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls. The input is as follows: >gi|1234|ref| Query = 1 - 65, Target = 1677 - 1733 Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46 fd sdfsdfsdfsdf fsdfdsfdfdfdfdfdf... (6 Replies)
Discussion started by: Amit1
6 Replies

3. Shell Programming and Scripting

Parse SQL text and only format first SELECT statement.

Hi Forum. Need your expertise on the following question. I have the following file which I would like to parse, find first block of SELECT statment and concatenate all input fields as 1 field (~ delimited): Old File: SELECT /*+ USE_HASH(CCOMM ICAR IMAP IAS IP IMAS IMPS IAP SPCA) */ ... (5 Replies)
Discussion started by: pchang
5 Replies

4. Shell Programming and Scripting

awk or sed to format text file

hi all, i have a text file which looks like the below 01 02 abc Top 40 music Kidz Only! MC 851 MC 852 MC 853 7NOW Arch_Diac xyz2 abc h211 Commacc1 Commacc2 Commacc3 (4 Replies)
Discussion started by: posner
4 Replies

5. Programming

awk script to convert a text file into csv format

hi...... thanks for allowing me to start a discussion i am collecting usb usage details of all users and convert it into csv files so that i can export it into some database.. the input text file is as follows:- USB History Dump by nabiy (c)2008 (1) --- Kingston DataTraveler 130 USB... (2 Replies)
Discussion started by: certteam
2 Replies

6. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

7. Shell Programming and Scripting

format text file

i have a text file in this format: name1^A1^B1^ name2^A2^B2^ ... namex^Ax^Bx^ name1^AA1^ name2^AA2^ ... namex^AAx^ name1^AAA1^BBB1^ name2^AAA1^BBB2^ ... namex^AAAx^BBBx^ name1^AAAA1^ name2^AAAA2^ ... namex^AAAAx^ i want to generate a file: (2 Replies)
Discussion started by: busystock
2 Replies

8. Shell Programming and Scripting

using awk to format text

I'm new to awk and would appreciate a jump start. I've got a text doc of people with first and last names, ages, home cities, and a phrase about the individual. I want to parse the text into fields and rows separated by tabs with the field names of - Firstname, Lastname, Age, City, Dollar... (5 Replies)
Discussion started by: jkandel
5 Replies

9. Shell Programming and Scripting

Format a text file

I have a file that gets created by pasting 3 files together to get the one file. The output of the 3 files follows. sft.rtf c3_critappdb_u5 start 04:22:20 end 08:03:41 c3_critappdb_u6 start 18:01:31 end 20:21:19 c3_critappdb_u7 start 00:02:50 end 08:30:17 c3_critappdb_u8 start 17:00:42 end... (2 Replies)
Discussion started by: jhardy
2 Replies

10. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies
Login or Register to Ask a Question