Command to update last line.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Command to update last line.
# 8  
Old 08-10-2011
That's one of the clever mechanisms I always forget about and sometimes grab an array heh, thanks Smilie
# 9  
Old 08-11-2011
Thanks zaxxon and alister,

I tried the code, in the output I could see the last line is gone.. Also I think in this logic we are counting the lines in the file and then replacing it. Please correct me if I'm wrong.

Also I have the count, I don't want to traverse to count the lines. but I need to replace the record count with entirely different number. I mean the count which is in the last line, I hv to replace exactly that without counting. Please suggest.
thanks in advance.
# 10  
Old 08-11-2011
?? Somebody or something has to count - else how would you know with which value you'll have to substitute the old value with? For this, Alister's solution should be better suitable than mine, especially for big files.

But if you already know how many lines there are minus the header and footer, you can just substitute the value in the last line directly.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use awk to update only 2nd line

I have a file and need to update the specific position on line two. I tried to use this solution under the post "Awk command to replace specific position characters" But need a way to just limit to update the line 2 and not every line on the file. awk 'function repl(s,f,t,v) { return... (1 Reply)
Discussion started by: Sandeep
1 Replies

2. Shell Programming and Scripting

Find and update line in xml file

Hi, I have a xml file that I need to modify 1 line to change some value from 2 to 10 (or any number). Sample input: <!-- some text here> . . . <message:test name="ryan"> <message:sample-channel charset="UTF-8" max-value="2" wait="20"> ... (5 Replies)
Discussion started by: brichigo
5 Replies

3. Shell Programming and Scripting

sed insert new line does not update file

Hi all, I have a file called "text.cpp" with the first line of "1" afterwards I tried in Ubuntu to type the following sed '12iasdasdasdasdsad' test.cpp > output.txt however when I tried to see the result of output.txt #cat output.txt 1 why is the line 12 is not updated to the... (6 Replies)
Discussion started by: peuceul
6 Replies

4. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

6. Shell Programming and Scripting

Update single line

Hi everyone i need one help don't know whether it is simple or difficult but not able to solve it. here is the problem suppose my code is time_def=3 r=0 while ] do echo "time left is $time_def " ((time_def=time_def-1)) done and the output is time left is 3 time left... (6 Replies)
Discussion started by: aishsimplesweet
6 Replies

7. Shell Programming and Scripting

How to find spaces and update values on the same line.

Dear all, I'm trying to write a script where: A file contains more or less 2000 lines. To some of those lines, in a specific position, let's say 89-92 there are spaces. So, this script should find these spaces on specific position and update a value (from 2 to 1) to another position of the... (4 Replies)
Discussion started by: paniklas
4 Replies

8. UNIX for Dummies Questions & Answers

Python update already printed line.

Hi. I have a basic script in python that outputs like this.. $ ./test.py 1% 2% 3% 4% 5% 6% 7% 8% 9% 10% ... But how can I make it so the output stays in 1 line? So it would look something like this.. $ ./test.py 10% (1 Reply)
Discussion started by: cbreiny
1 Replies

9. UNIX for Dummies Questions & Answers

Update a particular line in a file

Hii to all.. I have a file stud.lst bash-3.1$ cat stud.lst NO NMAE DOB 10 +2 BE AVG 075 syam saksena 12/12/55 500 398 550 48.26 099 sachin 11/05/47 450 500 600 51.66 300 mohan kumar 19/04/43 500 600 700 60.00 100 john 12/12/52 800 750 700 75.00 125... (2 Replies)
Discussion started by: krishnampkkm
2 Replies
Login or Register to Ask a Question