LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-08-2010, 06:27 AM   #1
himu3118
Member
 
Registered: Mar 2010
Posts: 35

Rep: Reputation: 15
append variable string in a specific line


I want to append a variable string to the end of a specific line. not like append the same string to each line.

like in my file i have 4 columns, i want to add a string in 5th column in some fixed row.

Any help will be very welcome.

Thanks in advance..
 
Old 06-08-2010, 07:30 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
It would help if you gave a few details. Post an example of what the text looks like; i.e. the before and after states of the file. Also, how will you match the line? By line number, or by some content?

In any case, either sed or awk can do what you want quite easily.
 
Old 06-08-2010, 07:44 AM   #3
himu3118
Member
 
Registered: Mar 2010
Posts: 35

Original Poster
Rep: Reputation: 15
i am putting the output of time command into a file.
like
/usr/bin/time -f -o -a abc.txt "\t%E Real-time \t%S TotalCPUseconds"
and after that in the same line i want to put some file name abns.txt

like: 0:00.00 Real-time 0.00 TotalCPUseconds abns.txt

but its doing like
0:00.00 Real-time 0.00 TotalCPUseconds
abns.txt..

may be i need to remove end of line from time output??
 
Old 06-08-2010, 08:25 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,017

Rep: Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196
I am not sure I understand the issue??
You already have free text in your output, so why not just add the file name on the end:
Code:
/usr/bin/time -f -o -a abc.txt "\t%E Real-time \t%S TotalCPUseconds abns.txt"
 
Old 06-08-2010, 08:49 AM   #5
himu3118
Member
 
Registered: Mar 2010
Posts: 35

Original Poster
Rep: Reputation: 15
thanx

Last edited by himu3118; 07-05-2010 at 04:41 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to append a string to a next line in perl tprayush Programming 1 04-09-2010 12:00 PM
using sed to append a variable after a certain line jadeddog Programming 6 11-05-2008 12:49 AM
Append variable string(s) at end of each line schaganti Linux - Newbie 2 10-19-2007 01:31 PM
bash: append string to end of line khairil Programming 6 02-27-2007 05:09 AM
batch append string to the end of a determined line in text files osio Programming 6 06-30-2005 09:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:42 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