Visit Our UNIX and Linux User Community


using awk for volatile column list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using awk for volatile column list
# 1  
Old 08-17-2007
using awk for volatile column list

Hi guys

I have my 5th column like this

12
12:00
12:13:14
5-12:13:14

Meaning

5 days 12 hrs 13 minutes and 14 seconds

I need to split this column into above meaning format. But all other columns are separated by single while space.

I am using awk command to print other columns. please help me here!

% yorker
# 2  
Old 08-18-2007
i don't follow what needs to 'split'. give a sample input and a desired output using the VBcodes
# 3  
Old 08-18-2007
The 5th column value "5-12:13:14" should be converted into "5 days 12 hrs 13 minutes and 14 seconds" and stored into table in the database.. This value will be like 13:14 meaning that 13 hours and 14 seconds, read from right to left, I think you can follow this now..pls let me know if you still want more accurate. But this column
# 4  
Old 08-18-2007
'what is a 'column'?
how are your records separated?
Is this '5-12:13:14' is only valid format of what needs to be 'split' and reformated or is e.g.'12' also valid (meaning '12 seconds')?
a couple of sample records/lines with varying values would be helpful (obviously).

pls use VB codes when giving samples.
# 5  
Old 08-18-2007
given yorker.txt
Code:
12
12:00
12:13:14
5-12:13:14

and yorker.awk
Code:
BEGIN {
  FS="[:-]"

  timeN=split("seconds minutes hrs days", timeA, " ")
}
{
   for(i=1; i<=NF; i++)
     printf("%s%s %s", (i==1)?"":" ", $i, timeA[NF-i+1])
   print ""
}

nawk -f yorker.awk yorker.txt
produces:
Code:
12 seconds
12 minutes 00 seconds
12 hrs 13 minutes 14 seconds
5 days 12 hrs 13 minutes 14  seconds

# 6  
Old 08-18-2007
Sample records
---------------
# Name Time
1 Elvis 12
2 Victor 12:00
3 Yorker 12:13:14
4 Prince 5-12:13:14

The columns are separated by white space..but if you look at the 'time' column, the format is not very standard..it can be seconds alone, or combination of minutes and seconds, or combination of hours, minutes,and seconds. But days if there is "-" (hyphen), it means time is more than 24 hours and they converted it into days.

Eg.

5-12:13:14

Meaning

5 days 12 hrs 13 minutes and 14 seconds

got me?
# 7  
Old 08-18-2007
look at my previous post.
it looks like you have THREE columns - not 5 you stated originally.
given your sample input file, what would the expected output be?

Previous Thread | Next Thread
Test Your Knowledge in Computers #467
Difficulty: Easy
In computer networking, telecommunication and information theory, broadcasting is a method of transferring a message to all recipients using reverse polish notation.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problems with awk (fatal error) and paste (two variables into one column-by-column)

Hello, I have a script extracting columns of useful numbers from a data file, and manipulating the numbers with awk commands. I have problems with my script... 1. There are two lines assigning numbers to $BaseForAveraging. If I use the commented line (the first one) and let the second one... (9 Replies)
Discussion started by: vgbraymond
9 Replies

2. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

3. UNIX for Dummies Questions & Answers

Creating a two column list of date pairs form a single column list

Hi all, looking for some help here. I'm what you'd call a dirty programmer. my shell scripts might be ugly, but they (usually) function... Say I have a single column text file with a list of dates (yyyymmdd) that represent the elevation of a point on that date (I work with land subsidence, so... (2 Replies)
Discussion started by: jbrandt1979
2 Replies

4. Shell Programming and Scripting

Any solution with awk for volatile columns??

Hi I have this file with content ale,4 ,ale,2 ,ale,1 ,ale,2 ale,1 ,ale,7 ,ale,7 ,ale,13 ale,6 ,ale,1 ,ale,1 ,ale,1 ale,1 ,ale,1 ,ale,37 ,ale,1 ale,1 ,ale,1 ,ale,2 ,ale,37 ale,77 ,ale,1 ,ale,53 ,ale,3 ale,5 ,ale,1 ,ale,2 ,ale,40 ale,1 ,ale,1 ,ale,44 ,ale,1... (7 Replies)
Discussion started by: nikhil jain
7 Replies

5. UNIX for Dummies Questions & Answers

Creating a column based list from a string list

I have a string containing fields separated by space Example set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex" and want to display it in a column format, for example to a maximum of a window of 100 characters And hopefully display some thing like Fred Ted Joe ... (3 Replies)
Discussion started by: kristinu
3 Replies

6. Shell Programming and Scripting

Construct 3 column table from one column list

Hi all! trying my best to parse a public site for information (ie fiscal year and turnover) about corporations. Doing this by having a file with business name and registration number (search key) the file bolag.txt currently looks like this Burgundy 556732-7217 AcademicSearch 556406-9879... (11 Replies)
Discussion started by: martindebruin
11 Replies

7. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

8. AIX

mkinstallp mark a file as volatile

I want to make a bff installp package which should be AIX5.2 compatible, but i don't know how to mark a file as volatile within the mkinstallp's template file. Anyone could help pls? (1 Reply)
Discussion started by: acerlinux
1 Replies

9. Programming

volatile variable

give me the detail about volatile , applications, how to use volatile variable (2 Replies)
Discussion started by: vinodkumar
2 Replies

10. Programming

volatile

hi plz explain about volatile keyword in C language bye... (1 Reply)
Discussion started by: venkat_t
1 Replies

Featured Tech Videos