add string and time stamp on each line of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting add string and time stamp on each line of file
# 1  
Old 10-15-2012
MySQL add string and time stamp on each line of file

I have file A.txt

A 1023
B 123
C 1223

I want output

Code:
Hello_12PM_A 1023
Hello_12PM_B 123
Helll_12PM_C 1223

Add Hello and time stamp in AM and PM.
# 2  
Old 10-15-2012
Quote:
Originally Posted by asavaliya
I have file A.txt

A 1023
B 123
C 1223
Code:
Hello_12PM_A 1023
Hello_12PM_B 123
Helll_12PM_C 1223

Add Hello and time stamp in AM and PM.
I think this is almost same as this post
# 3  
Old 10-15-2012
No Men That's total different...

I want add string and time of each line of that file Smilie

i am tring with below command but no Luck
Code:
nawk '{print "Hello_`date +%Y_%m_%d_%H_%M`-" $0}' $A1 > $l1


Last edited by Franklin52; 10-15-2012 at 06:15 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 10-15-2012
Quote:
Originally Posted by asavaliya
No Men That's total different...

I want add string and time of each line of that file Smilie

i am tring with below command but no Luck

nawk '{print "Hello_`date +%Y_%m_%d_%H_%M`-" $0}' $A1 > $l1
You can use variables inside awk.

Code:
date_var=$(date +%Y_%m_%d_%H_%M)

nawk -v VM="$date_var" '{ print "Hello_"VM"-"$0}' $A1 > $l1

This User Gave Thanks to pamu For This Post:
# 5  
Old 10-15-2012
Bug

Perfect !!!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add current time stamp column in existing csv file

Hi , I want to add a new column 'current_time stamp' in my existing csv file with current time stamp for all the records.I tried something this but this is printing 0 with date & time and printed date one line above header.Please help awk -F "," 'BEGIN{ OFS="," } {$6=system("date... (5 Replies)
Discussion started by: netdbaind
5 Replies

2. Shell Programming and Scripting

Capturing time stamp in file name

I have a file that is created via a perl script where the file is named like so: 01-07-2016_10:17:08. I am running a shell script that needs to take this file and print it. I can capture the date portion fine, but I am unsure how to capture the time stamp, since there will be a difference from what... (1 Reply)
Discussion started by: ldorsey
1 Replies

3. Shell Programming and Scripting

How to add the dat time stamp just before the last extension of a file?

hi, A file name is in the form inside a variable FILE_NAME="s1.txt.xls" i want to append date and time stamp inbetween s1.txt and .xls. so after appending date time stamp the file name would be MOD_FILE_NAME="s1.txt.201307251422.xls" currently i am using the below code... (4 Replies)
Discussion started by: Little
4 Replies

4. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

5. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

6. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

7. Shell Programming and Scripting

Check file time stamp

Hi, I need help to read file in a directory on basis of time stamp. e.g. If file access in last 2 minutes it should not be copy to remote directory. Below is my script. #!/bin/ksh DATE=`date +"%Y-%m-%d_%H%M"` SEPARATER=" " exec < out_interfaces.cfg while read source_path... (10 Replies)
Discussion started by: qamar.alam
10 Replies

8. UNIX for Dummies Questions & Answers

Parsing file, reading each line to variable, evaluating date/time stamp of each line

So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated. Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies

9. Shell Programming and Scripting

file time stamp

Hi All, I am facing small problem. i want to print file time stamp on which date file has placed in the server. i have given some code but its not giving the year. any help appreciated. regards rajesh. (4 Replies)
Discussion started by: rajesh_pola
4 Replies

10. UNIX for Dummies Questions & Answers

File date and time stamp

I have to capture the creation date and time stamp for a file. The ls command doesn't list all the required information. I need year, month, day, hour, minute and second. Any ideas... (1 Reply)
Discussion started by: Xenon
1 Replies
Login or Register to Ask a Question