Replacing a numeric string with a sequence of numbers
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Try the `sort` command; perhaps something (off top of my head, and assuming that the number on the first line is the LOWEST of the numbers) like `sort -t , -u -k2 $filename > $new_filename` though you'll definitely want to look up the right syntax in the man page.
Last edited by GrapefruiTgirl; 06-21-2009 at 11:36 AM.
Reason: fixed the field separator; may need to actually SED the commas to spaces, then back
Try the `sort` command; perhaps something (off top of my head, and assuming that the number on the first line is the LOWEST of the numbers) like `sort -t- -u -k2 $filename > $new_filename` though you'll definitely want to look up the right syntax in the man page.
Wouldnt the sort command just sort the numbers? I dont just want to sort them i want them to be in sequence i.e. 5,3,4,7,9 to change to 5,6,7,8. Just sorting them would result in 3,4,5,7,9.
Yes thats exactly what i needed. Apologies my English is not very top class
So what exactly is happening there?
What you really wanted was to have a sequence
in the second column, starting with the value of
the first row (discarding all values previously
in column two). What the awk script does is to
store the first value [if we're on the first line
(NR==1)], and then just keeps adding one to the
start value for any row we encounter, replacing
the value in column 2 ($2, which we initially read
in the first row) with the value of start, while
leaving column 1 and 3 intact. Really I should have
called the thing sequence rather than start to make
it clearer - but I only just crawled out of bed ;D