using awk for volatile column list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using awk for volatile column list
# 8  
Old 08-18-2007
Thank you , I appreciate your time for me, I think this will work out for me, but need to test this against table.
# 9  
Old 08-18-2007
given yorker.txt:
Code:
# Name Time
1 Elvis 12
2 Victor 12:00
3 Yorker 12:13:14
4 Prince 5-12:13:14

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

  FLDtime="3"

  timeN=split("seconds minutes hrs days", timeA, " ")
}
/^#.*/ { print; next }

{
   _tmpN=split($FLDtime, _tmpA, SEPtime)

   timeS=""
   for(i=1; i<=_tmpN; i++)
     timeS = timeS sprintf("%s%s %s", (i==1)?"":" ", _tmpA[i], timeA[_tmpN-i+1])
   $3= "'" timeS "'"
   print
}

nawk -f yorker.awk yorker.txt
produces:
Code:
# Name Time
1 Elvis '12 seconds'
2 Victor '12 minutes 00 seconds'
3 Yorker '12 hrs 13 minutes 14 seconds'
4 Prince '5 days 12 hrs 13 minutes 14 seconds'

Login or Register to Ask a Question

Previous Thread | Next Thread

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
Login or Register to Ask a Question