Computing.Net > Forums > Unix > Insert Date at the end of everyLine

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Insert Date at the end of everyLine

Reply to Message Icon

Name: nish_r
Date: August 24, 2006 at 23:10:57 Pacific
OS: UNIX
CPU/Ram: 512
Comment:

Hi,

I need to insert today's date (dd-mm-yyyy) at the end of each and every line in a text file. I nees #!/bin/sh.


My file as follows.
-------------------------

one , three , ten , five
twelve , ten , five , one
...............................
...............................
one , two , nine , eight

Output file should be:


one , three , ten , five , 25-08-2006
twelve , ten , five , one, 25-08-2006
...............................
...............................
one , two , nine , eight, 25-08-2006


Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: August 25, 2006 at 08:50:59 Pacific
Reply:

#!/bin/ksh

var=$(date '+%d-%m-%Y')

# using the shell
while read line
do
printf "%s,%s\n" "$line" "$var"
done < text.file

# using awk

awk ' { printf("%s,%s\n", $0, v1) } ' v1="$var" text.file

# using sed

sed "s/$/,$var/" text.file


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Insert Date at the end of everyLine

Inserting a string at the end of a www.computing.net/answers/unix/inserting-a-string-at-the-end-of-a-/6205.html

How to get rid of a "," at the end of a variable read www.computing.net/answers/unix/how-to-get-rid-of-a-at-the-end-of-a-variable-read/1186.html

to append the end of a line www.computing.net/answers/unix/to-append-the-end-of-a-line/6100.html