LinuxQuestions.org
Visit Jeremy's Blog.
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 10-16-2012, 11:15 PM   #1
smturner1
Member
 
Registered: Oct 2009
Location: MI
Distribution: Arch 2.6.35
Posts: 107

Rep: Reputation: 1
Referencing an array against a var


Here I am reading the records in all files in the current dir ending in inv and storing the value in x and y, column 2 and column 4 respectively.
Code:
{
     x=`awk -F"|" '{print $2}' *inv` 
     y=`awk -F"|" '{print $4}' *inv`
}
ABOVE: I am not sure if I can call the file with *inv and read the contents of the file.

BELOW: I am trying to set up an array for 'x' to reference.
Code:
    biller_id[1 "a.file"
	      2 "b.file"
	      3 "c.file"
	      4 "d.file"
	      5 "e.file"
	      6 "f.file"
	      7 "g.file"
	      8 "h.file"
	      9 "i.file"
	      10 "j.file"
BELOW: I am tring to get the value for 'x' so I can create a file in the current dir and copy the value(s) from 'y' to it.
Code:
for $x in (biller_id)
do 
	print $y >> $x[]#<---I realize this is wrong!
done

basically what is supposed to happen is that the script reads all the records of a file; grabs the appropriate values per columns and stores the value of y in file named x.

I am certain there are a few issues. Please let me know where I went wrong and what is proper. I prefer to learn so I do not keep repeating the same mistakes.

Thank you.
s
 
Old 10-17-2012, 10:38 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
I am not sure I follow?
Quote:
grabs the appropriate values per columns and stores the value of y in file named x.
How is this any different than your previous question?

And what does all the information at the start have to do with this solution?
 
Old 10-17-2012, 11:43 AM   #3
smturner1
Member
 
Registered: Oct 2009
Location: MI
Distribution: Arch 2.6.35
Posts: 107

Original Poster
Rep: Reputation: 1
grail,

I resolved this issue. I just used a case and tested the value against the list. It works and I am satisfied.

I was just kicking around some better ways to approach my issue. Sorry for the confusion. The way I figure it, learn good, efficient coding techniques and reduce resource time and money during execution. Also it doesn't hurt to be the envy of your department.

s
 
Old 10-17-2012, 12:04 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
Quote:
Originally Posted by smturner1 View Post
The way I figure it, learn good, efficient coding techniques and reduce resource time and money during execution. Also it doesn't hurt to be the envy of your department.
It will probably be much more efficient to code the whole thing in awk, certainly the code you posted that runs awk over every file twice is going to be quite inefficient. It's hard to make more suggestions because you've only shown tiny parts of your problem.
 
  


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
LaTeX Referencing (Harvard Style) Gavin Harper Programming 1 03-31-2011 12:01 PM
Java: Referencing an image within a package indienick Programming 3 02-01-2009 11:02 PM
BASH variable referencing SwingingSimian Programming 3 10-16-2008 06:20 AM
referencing a file - newbie question FastOwl MEPIS 4 07-05-2005 04:35 PM
sed back referencing pauljtester Linux - Software 2 11-11-2004 05:20 PM


All times are GMT -5. The time now is 05:14 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