LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices


Reply
  Search this Thread
Old 12-16-2009, 01:38 AM   #16
jayran
LQ Newbie
 
Registered: Dec 2009
Posts: 14

Original Poster
Rep: Reputation: 0

Code:
IFS=$'\n'; arr=( $( < arts1.tsv ) );
for ((i=0; i<$((${#arr[@]})); i++)); do 
   echo "${arr[$i]}" | tr "[[:space:]]" '\n' | grep -v '^$' | sort | uniq >> ar; 
   sed -i -e 's/^/ /;s/$/ /' ar; 
   while read line <&3; do 
       sed -i -e "s/[[:space:]]$line[[:space:]]/ /g" ar; 
   done 3<stopwords; 
   cat ar | sed "s/[[:space:]]//g" | grep -v '^$' > aar; 
   mv aar ar; 
   num="1"; 
   while read line <&5; do 
       while read LINE <&4; do 
            if [ "$line" == "$LINE" ]; then 
                echo "$num" >> artres; 
            fi; 
       done 4<ar; 
       ((num++)); 
   done 5<word.tsv; 
   artarr[$i]=`cat artres`; 
   rm ar; rm artres; 
done
aha, got it!!
 
Old 12-16-2009, 01:40 AM   #17
jayran
LQ Newbie
 
Registered: Dec 2009
Posts: 14

Original Poster
Rep: Reputation: 0
also another question... can i load this array into matlab? then i can make a matrix out of it maybe there... but how can i save this array ??? i know very little about coding in bash and stuff... maybe i can, can i?
 
Old 12-16-2009, 01:42 AM   #18
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
and where are your input samples and output ? your shell script is badly written. A lot of redundant calls to external tools that do the same thing. your script is going to perform poorly on big data.
 
Old 12-16-2009, 01:55 AM   #19
jayran
LQ Newbie
 
Registered: Dec 2009
Posts: 14

Original Poster
Rep: Reputation: 0
yes i know. this is my first attempt at coding... by extrenal tools you mean ...? how can i fix them?
my data sample, arts1.txt is attached ; i cut it short. it didnt let me attach it in .tsv format. my code is still running, so i have no output yet.
Attached Files
File Type: txt arts1.txt (4.5 KB, 3 views)

Last edited by jayran; 12-16-2009 at 02:00 AM.
 
Old 12-16-2009, 02:00 AM   #20
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by jayran View Post
also another question... can i load this array into matlab? then i can make a matrix out of it maybe there..
i already told you , you can do all these in matlab. It will be the same procedure, opening of your file, loading the data into matlab arrays, doing your matrix manipulation and closing your files. All it takes is search and read the mathworks documents. or search google. here's one example to read/save files
 
Old 12-16-2009, 02:04 AM   #21
jayran
LQ Newbie
 
Registered: Dec 2009
Posts: 14

Original Poster
Rep: Reputation: 0
yes i was reading dlmread. I will try that tomorrow morning when i wake up.
Another question what did you mean by external tools?
thanks a loooot.
 
Old 12-16-2009, 02:19 AM   #22
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by jayran View Post
Another question what did you mean by external tools?
thanks a loooot.
those that are not built into the shell. eg awk, sed, grep, sort, uniq, cat, wc etc...
 
Old 12-16-2009, 08:21 AM   #23
jayran
LQ Newbie
 
Registered: Dec 2009
Posts: 14

Original Poster
Rep: Reputation: 0
good morning. so how can I avoid using those external tools? what would one use instead of sed...? or should i just try to limit my use of those?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ array question on non assigned elements davimint Programming 9 11-24-2008 10:43 AM
trimming perl array elements homey Programming 7 02-17-2008 04:48 PM
print array elements in one line bharatbsharma Programming 1 10-29-2007 09:58 AM
Simultaneous writes into different elements of an array estratos Programming 7 12-15-2006 07:36 AM
Renaming array elements in bash bryan.out.there Programming 2 06-01-2006 12:44 AM


All times are GMT -5. The time now is 02:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration