Adding a timestamp every N row in another column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding a timestamp every N row in another column
# 1  
Old 04-12-2017
Adding a timestamp every N row in another column

Hi,
i have a raw output file like this

Code:
167,63.50

167,63.50

168,63.68

166,63.68

168,63.68

I would like to add every each N rows (for example 60) and in a third column , a timestamp using the command
Code:
date +"%H:%M"

how can i do it with one single command ?

Thank you !!
# 2  
Old 04-12-2017
Hello Board27,

Could you please try following and let me know if this helps you.
Code:
 awk -v DATE=$(date +"%H:%M") -v var=3 'FNR%var==0{print $0,DATE;next} 1'   Input_file

Here in above code I have given value of line as 3 you could change it to as per your need.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 04-12-2017
it comes :

Code:
314,63.14
 12:22

it is not adding a column with comma. Anyway i express myself in a wrong way. I don't need each N time. I just need to add timestamp at a certain line, for example, if my file has 1000 lines , add a timestemp to the 60th line, 3th column with comma divider.

Thank you anyway for your help!
# 4  
Old 04-12-2017
Hello Board27,

Could you please try following and let me know if this helps you.(Change var's value to your needed line number)
Code:
awk -v DATE=$(date +"%H:%M") -v var=3 'FNR==var{print $0","DATE;next} 1'   Input_file

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 04-12-2017
thanks
# 6  
Old 04-13-2017
Try also
Code:
awk -v DATE=$(date +"%H:%M") -v var=3 'NR==var {$(NF+1) = DATE} 1' OFS=","  file2
167,63.50

167,63.50,22:02

168,63.68

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Transpose from row to column using timestamp in first column

Gents, Transpose from row to column, taking in consideration the first column, which contends the date. Input file 72918,111000009,111000009,111000009,111000009,111000009,111000009,111000009,111000009,111000009 72918,2356,2357,2358,2359,2360,2361,2362,2363,2364 72918,0,0,0,0,0,0,0,0,0... (12 Replies)
Discussion started by: jiam912
12 Replies

2. Shell Programming and Scripting

Print first row of column a, last row of column b if column a has the same value

I have a table with this structure: cola colb colc 1 19 lemon 20 31 lemon 32 100 lemon 159 205 cherries 210 500 cherries and need to parse it into this format: cola colb colc 1 100 lemon 159 500 cherries So I need the first row of cola and the last row of colb if colc has the... (3 Replies)
Discussion started by: coppuca
3 Replies

3. Shell Programming and Scripting

Print row on 4th column to all row

Dear All, I have input : SEG901 5173 9005 5740 SEG902 5227 5284 SEG903 5284 5346 SEG904 5346 9010 SEG905 5400 5456 SEG906 5456 5511 SEG907 5511 9011 SEG908 5572 9015 SEG909 5622 9020 SEG910 5678 5739 SEG911 5739 5796 SEG912 5796 9025 ... (3 Replies)
Discussion started by: attila
3 Replies

4. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

5. UNIX for Dummies Questions & Answers

Adding a column to a text file with row numbers

Hi, I would like to add a new column containing the row numbers to a text file. How do I go about doing that? Thanks! Example input: A X B Y C D Output: A X 1 B Y 2 C D 3 (5 Replies)
Discussion started by: evelibertine
5 Replies

6. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

7. Shell Programming and Scripting

Adding timestamp after cat <<EOF >

Hi Team, I am trying to add timestamp to SQLs by taking the timestamp in variable through shell script.I started like this. cat << EOF > $MYDIR CONNECT TO $MYDB USER $MYUSR USING $MYPWD; T=`db2 -x "select CURRENT_TIMESTAMP from sysibm.sysdummy1 "`; DECLARE RECCUR CURSOR FOR... (3 Replies)
Discussion started by: rocking77
3 Replies

8. Shell Programming and Scripting

Moving data from a specified column/row to another column/row

Hello, I have an input file like the following: 11_3_4 2_1_35 3_15__ _16989 Where '_' is a space. The data is in a table. Is there a way for the program to prompt the user for x1,y1 and x2,y2, where x1,y1 is the desired number (for example x=6 y=4 is a value of 4) and move to a desired spot... (2 Replies)
Discussion started by: jl487
2 Replies

9. UNIX for Dummies Questions & Answers

Adding a column with the row number using awk

Is there anyway to use awk to add a first column to my data that automatically goes from 1 to n , where n is the numbers of my rows?:confused: (4 Replies)
Discussion started by: cosmologist
4 Replies

10. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies
Login or Register to Ask a Question