Editting a record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Editting a record
# 1  
Old 02-22-2013
Wrench Editting a record

robert

Last edited by robert89; 02-24-2013 at 08:09 AM..
# 2  
Old 02-22-2013
Will the 0 always start at same position, so this is the actual number 00001453. If not, the is some difficult since your tail do contain several group of 0
# 3  
Old 02-22-2013
Try:
Code:
a=1453
sed -n "\$s/[1-9]*\$/$a/p" file

# 4  
Old 02-22-2013
@Don: applying your code snippet to a file containing requestor's line yields
Code:
$ sed -n "\$s/[1-9]*\$/$a/p" file
1453290070331000012923

Am I missing sth?

EDIT: Yes I did! That input sample above had a <CR> char in it causing that strange result. Using Don's code on a normal unix file works as expected - his reputation fully rehabilitated... Sorry for me falling into that trap.


I came up with
Code:
$ sed  "$ s:[^0]*$:$a:" file
.
.
.
T005290070331000012923
T005290070331000012923
T00529007033100001453

as the request left open if the entire file should be reproduced or just the modified last line.

EDIT 2: neither proposal works if there is a 0 contained within that last 5 digit number, e.g. 12023...

Last edited by RudiC; 02-22-2013 at 11:32 AM.. Reason: discovered <CR> chars after a while
# 5  
Old 02-22-2013
Quote:
Originally Posted by RudiC
@Don: applying your code snippet to a file containing requestor's line yields
Code:
$ sed -n "\$s/[1-9]*\$/$a/p" file
1453290070331000012923

Am I missing sth?
I came up with
Code:
$ sed  "$ s:[^0]*$:$a:" file
.
.
.
T005290070331000012923
T005290070331000012923
T00529007033100001453

as the request left open if the entire file should be reproduced or just the modified last line.
Hi Rudi,
I used sed -n because the requested output in the 1st message in this thread only showed one line.

From the way the request was worded, I'm not even sure if there is more than one line in the input file. (I don't know if "tail" refers to the last line in the file or to the end of the last (and maybe only) line in the file.
# 6  
Old 02-22-2013
Wrench

robert

Last edited by robert89; 02-24-2013 at 08:09 AM..
# 7  
Old 02-23-2013
Quote:
Originally Posted by robert89
So please suggest a better code .
What about considering all the proposals - that, btw, satisfy your original requirements - and develop a "better" code yourself? On top, your specification left quite some questions open that occurred in the discussion - pls answer them first.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need code for updating second record to first record in shell scripting

Hi,, I have requirement that i need to get DISTINCT values from a table and if there are two records i need to update it to one record and then need to submit INSERT statements by using the updated value as a parameter. Here is the example follows.. SELECT DISTINCT ID FROM OFFER_GROUP WHERE... (1 Reply)
Discussion started by: Samah
1 Replies

2. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

3. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

4. Linux

Problem editting the first occurence of a pattern in the first uncommented line

Hi I have to replace a pattern found in the first uncommented line in a file. The challenge I'm facing is there are several such similar lines but I have to edit only the first uncommented line. Eg: #this is example #/root/xyz:Old_Pattern /root/xyz:Old_Pattern /root/xyz:Old_Pattern ... (10 Replies)
Discussion started by: Stoner008
10 Replies

5. Shell Programming and Scripting

Reject the record if the record in the next line does not satisfy the pattern

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten The output should be 1one 2two 3three 1four 2five 3six (2 Replies)
Discussion started by: supchand
2 Replies

6. Shell Programming and Scripting

Editting each line in a file

Hi Can anyone please help me in resolving my issue. I have a file with entries like this t9787ms 99970 22/08/2010 12:30 /www.google.com t9788ms 99942 22/08/2010 12:40 /www.google.com t4788ms 88942 22/08/2010 01:40 /www.google.com there are around 5 lakh records of this type my requirement... (4 Replies)
Discussion started by: mskalyani
4 Replies

7. UNIX for Dummies Questions & Answers

matching IDs from two files and editting

I have two files. One has: ID# 0 a b c d e f g h i j k....................~2 milion columns ID# 0 l m n o p q r s t u v....................~2 milion columns . . . ~6000 lines Other has: ID# 1 or ID# 2 . . ~6000 lines (2 Replies)
Discussion started by: polly_falconer
2 Replies

8. Shell Programming and Scripting

editting file

Hi, I am having sequence of process ids in one file. My file contents is (Output of fuser someobject.so). 654 14583 17890 25902 This no. of processes may vary depends up on the object. I want to check all the processes one by one. If i want to apply egrep, I need to... (3 Replies)
Discussion started by: sharif
3 Replies

9. Shell Programming and Scripting

Unix file editting commands

ok, are there any other file editting commands out there other than the below that comes with sunsolaris & linux vi, emacs, ed, (1 Reply)
Discussion started by: Terrible
1 Replies

10. Shell Programming and Scripting

file editting with shell programmin

Hello, I have several handreds of text files. The format of file looks like: column1 column2 column3 column4 column5 id1 definition1 name1 fieldid comm1 id2 definition2 name2 fieldid ... (4 Replies)
Discussion started by: ssshen
4 Replies
Login or Register to Ask a Question