LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-25-2014, 08:42 AM   #1
davidcummings
LQ Newbie
 
Registered: Jul 2014
Posts: 3

Rep: Reputation: Disabled
Add Date to end of each line a txt


Hi,
I have the following script:

#!/bin/sh
/bin/mv /root/dump1090/radar.txt /root/logs/radar.txt
/bin/touch /root/logs/dump1090/radar.txt
/usr/bin/awk '!_[$1]++' /root/logs/radar.txt >/root/logs/radar1.txt
/bin/sed 's/$/,20140001,//' /root/logs/radar0.txt >/root/logs/radar1.txt
/bin/mv /root/logs/radar2.txt /root/logs/radar.csv
/bin/mv /root/logs/radar.csv /root/logs/"radar-`date +%Y%m%d`.csv"



How do I get the date in the format of

YYYY-MM-DD added to this line after the second comma:

/bin/sed 's/$/,20140001,//' /root/logs/radar0.txt >/root/logs/radar1.txt

thanks in advance
David
 
Old 07-25-2014, 09:02 AM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Can you paste the section where you need the modification in radar1.txt post running sed on it. Just use bold tag to highlight it.
 
Old 07-25-2014, 09:07 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Rather than us provide the answer, perhaps you should show us what you tried - and what you don't understand about why it didn't work.
 
Old 07-25-2014, 09:23 AM   #4
davidcummings
LQ Newbie
 
Registered: Jul 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Its on this line :
Code:
/bin/sed 's/$/,20140001,//' /root/logs/radar0.txt >/root/logs/radar1.txt

I have tried adding `date +%Y%m%d` to it :

Code:
/bin/sed 's/$/,20140001,`date +%Y%m%d`//' /root/logs/radar0.txt >/root/logs/radar1.txt
but it didnt run
 
Old 07-25-2014, 06:41 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Use doube quotes(") rather than single (') around the substitution text - that way the date command will get evaluated by the shell.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a FileID and delete one line for 900 txt files Migasi Linux - Newbie 2 03-04-2014 03:52 PM
[SOLVED] Add symbol to the end of every other line Adzrules Linux - Newbie 3 11-15-2012 10:01 AM
sed add a character to the end of each line keenboy Linux - General 2 08-05-2010 12:36 PM
add more than one line to end of file Siljrath Linux - General 1 08-18-2009 11:01 PM
add text to end of line? tatoosh Linux - Newbie 8 07-31-2009 03:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration