![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| convert ascii values into ascii characters | sandeeppvk | Shell Programming and Scripting | 10 | 04-23-2009 11:23 PM |
| Selectively Reformating a file using AWK | sda_rr | UNIX for Advanced & Expert Users | 5 | 03-23-2009 12:33 PM |
| awk - reformating rows into columns | jmd2004 | Shell Programming and Scripting | 1 | 08-13-2008 11:56 PM |
| How to convert English text file to ASCII File? | laknar | Shell Programming and Scripting | 1 | 07-23-2008 09:37 AM |
| Help on awk.. reformating a file | Martian | Shell Programming and Scripting | 4 | 08-06-2007 06:18 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Reformating ascii file with awk
Hello,
I've a lot of ascii files that I would like to reformat : One of files's column (for exemple $5) contains increasing numbers (see exemple) : $5= Code:
1 1 1 1 1 2 2 2 2 3 3 3 3 3 3 3 3 4 4 What I'd like to do is to assign the value "1" for the first record of a consistant block ( a block is defined by the same $5 number), "2" for middle records and "3" for the last one. Then another "1" for the next block, etc. : In my exemple, the file may become : $5= Code:
1 2 2 2 3 1 2 2 3 1 2 2 2 2 2 2 3 1 3 I've tested some stuff with awk but I always failed... If you've got some ideas to help me... you're welcome. Nico. ps : Please excuse my poor English, I'm from France ![]() ---------- Post updated at 04:23 PM ---------- Previous update was at 04:04 PM ---------- I've tryed this... Code:
awk '{l[NR]=$1};
{for(i=1;i<=NR;i++)
{if(l[i]!=l[i-1])print "1";
if(l[i]==l[i-1] && l[i]==l[i+1]) print "2";
if(l[i]!=l[i+1])print "3"}}' toto
Last edited by radoulov; 1 Week Ago at 03:45 AM.. Reason: added code tags |
|
||||
|
Thanks a lot radoulov..
It perfectly works... I've tested my ancient script in an Exceed emulated unix... It also works... (whereas it doesn't works on cygwin...) But your solution keeps all the others columns. It's perfect for me. For the moment I don't understand all the syntax of your script... but I'll try to study a little bit the problem. =) Caribou. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|