Computing.Net > Forums > Unix > uneven matrix

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

uneven matrix

Reply to Message Icon

Name: gpatel
Date: November 17, 2005 at 05:44:01 Pacific
OS: unix
CPU/Ram: 1GB
Comment:

hey all,
I have this file looks like this

A = [ 1 2 3 4 5
6 7 8 9 10 11
12 12 12 12
13 14 15 16
17 18 19 20 21 ]
i wanted to get rid of 2nd row and 5th row. any row that doesnt have the same column as the previous one. my problem in matlab is it will take too long. since i have about 13000 rows and 46 coulmns. can someone help w/ unix script. thanks,
Gpatel

thanks,
Gaurav



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: November 17, 2005 at 08:13:27 Pacific
Reply:

So, I'm assuming that you need to NOT process 'A = [' in the first line and ' ]' in the last line?

If that's the case, these characters need to be retained?



0

Response Number 2
Name: gpatel
Date: November 17, 2005 at 08:22:18 Pacific
Reply:

yes the file just look like this
1 2 3 4 5
6 7 8 9 10 11
12 12 12 12
13 14 15 16
17 18 19 20 21

there is no A and [];
file only has numbers and some rows are different then others. i wanted to delete those rows which are different.
thanks for your help nails.
~gpatel

thanks,
Gaurav


0

Response Number 3
Name: gpatel
Date: November 17, 2005 at 08:24:30 Pacific
Reply:

I meant to say differnt columns now rows.

thanks,
Gaurav


0

Response Number 4
Name: nails
Date: November 17, 2005 at 10:27:15 Pacific
Reply:

Here's my take: Read each line, determining the number of fields in each line. If the next line has the same number of lines, print it else if it doesn't delete it. When a line is deleted start the field count over:


awk ' BEGIN { cnt=0 }
{
if (cnt == 0)
{
pf=NF
cnt++
print $0
continue
}

if(cnt == 1)
{
if(pf == NF)
print $0
else
cnt=0
}
} ' data.file
# end script

In case you don't know, awk sets NF to the number of fields for the line read.

Let me know if you have any questions.


0

Response Number 5
Name: gpatel
Date: November 17, 2005 at 19:31:28 Pacific
Reply:

Thanks a lot. i know little bit about awk but thanks for explanation. I am going to try this and i will let you know. thanks one again.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: uneven matrix

matrix printer www.computing.net/answers/unix/matrix-printer/2812.html

Edit Matrix using shell script www.computing.net/answers/unix/edit-matrix-using-shell-script/7573.html

Help on my S3 Virge/DX ART 375 video card www.computing.net/answers/unix/help-on-my-s3-virgedx-art-375-video-card/154.html