Parsing records in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing records in file
# 1  
Old 06-13-2012
Parsing records in file

have a datafile that contains:
Code:
Jun 13 12:59:21
Jun 13 13:02:04
Jun 13 13:14:21

i want to parse this so they look like this:

Code:
Jun 13 12:59
Jun 13 13:02
Jun 13 13:14

how can i do this? basically wanna get rid of the seconds.

i'd prefer this to be a one liner.

command | awk blah blah

shell: bash

Last edited by SkySmart; 06-13-2012 at 12:33 PM..
# 2  
Old 06-13-2012
Please post sample data for a single digit day.
# 3  
Old 06-13-2012
Quote:
Originally Posted by methyl
Please post sample data for a single digit day.

the date format is exactly the same as that of the unix messages file.

meaning:

Code:
Jun  8 13:02:04
Jun 10 14:05:98

notice the two spaces in the single digit date
# 4  
Old 06-13-2012
Code:
$ awk -F: 'sub(FS $NF,z)' file
Jun 13 12:59
Jun 13 13:02
Jun 13 13:14

This User Gave Thanks to cabrao For This Post:
# 5  
Old 06-13-2012
Code:
cut -c-12 file

Code:
colrm 13 <file


Last edited by Scrutinizer; 06-13-2012 at 06:25 PM..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Separate records of a file on 2 types of records

Hi I am new to shell programming in unix Please if I can provide help. I have a file structure of a header record and "N" detail records. The header record will be the total number of detail records I need to split the file in 2: One for the header Another for all detail records Could... (1 Reply)
Discussion started by: jamcogar
1 Replies

2. Shell Programming and Scripting

Deleting duplicate records from file 1 if records from file 2 match

I have 2 files "File 1" is delimited by ";" and "File 2" is delimited by "|". File 1 below (3 record shown): Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Discussion started by: vestport
2 Replies

3. Shell Programming and Scripting

Need a very specific awk command for parsing records

I have data in a file where the first line of the file identifies the fields. I need to be able to parse out any single record, field-by-field, with the fields identified. So if my file looks like this: NAME, ADDRESS, PHONE Jim Smith, 123 Main Street, 999-888-7777 Bob Jones, 555 Park Avenue,... (6 Replies)
Discussion started by: Finja
6 Replies

4. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

5. Shell Programming and Scripting

Parsing record into multiple records in Shell Script

Hi, I am trying to parse a very long record in a text file into multiple records by checking ADD, DELETE, or MODIFY field value in a shell script. Input # File name xyz.txt ADD|N000|8015662|DELETE|N001|9915662|MODIFY|N999|85678 Output ADD|N000|8015662| DELETE|N001|9915662|... (8 Replies)
Discussion started by: naveed
8 Replies

6. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

7. UNIX for Dummies Questions & Answers

Use records from one file to delete records in another file

file_in_1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 file_in_2: 9 10 11 12 21 22 23 24 1 2 3 4 17 18 19 20 file_out: (5 Replies)
Discussion started by: kenneth.mcbride
5 Replies

8. UNIX for Advanced & Expert Users

Parsing records from one record

Hi, I got a file which is one huge record. I know each record should be 550 bytes long. How do I parse out the records from the one huge record. (1 Reply)
Discussion started by: bwrynz1
1 Replies

9. UNIX for Dummies Questions & Answers

Parsing out records from one huge record

Hi, I have one huge record and know that each record in the file is 550 bytes long. How do I parse out individual records from the single huge record. Thanks, (4 Replies)
Discussion started by: bwrynz1
4 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question