I'm writing my first bash function, and I'm having a little bit of trouble getting used to the syntax. I have been told that it is very similar to Java, but I'm still not quite getting it.
The situation that I am dealing with is checking the values on input fields. There will be anywhere between two and five fields, so the code has to be able to adapt. The fields with either be a string, or a number. This is what I have so far...I am also using the match function, which I have never used before.
This function takes place within a file, which is used as a set of rules to be executed in an awk statement.
So, my question is, is there a way to have a pointer for the current field? I need to check each one, one by one, every time. I haven't been able to find this answer anywhere else, so I'm hoping someone can help me out.
Also, does the function in bash take parameters? Or would it be executed get( current field variable...???) or currentfieldvariable.get()?
I don't really need help with the "do something else" part of the code, because I know how to do it.
BASH has variable references ala ${!VARNAME}, if VARNAME is ABC will give you the value of $ABC
Setting the variable through a reference is harder though, you have to build a shell statement and feed it into eval.
It would probably help to see your code, there may be ways to do this without using references of any sort.
Functions do indeed take parameters. Parameter 1 becomes $1, parameter 2 becomes $2, etc. You can use shift to put it in a loop -- it pops off the first parameter, making $2 into $1, $3 into $2, etc.
Last edited by Corona688; 07-29-2011 at 01:29 PM..
Reason: forgot the shift!
Table
ACN|NAME|CITY|CTY|NO1|NO2
115|AKKK|ASH|IND|10|15
115|AKKK|ASH|IND|20|20
115|AKKK|ASH|IND|30|35
115|AKKK|ASH|IND|30|35
112|ABC|FL|USA|15|15
112|ABC|FL|USA|25|20
112|ABC|FL|USA|25|45
i have written shell script using cut command
and awk programming getting error correct it and add... (5 Replies)
I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below:
column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10
"12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Hi Everyone,
New to the forum, and have my first question.
I have the following Macro currently being used within Telnet to run a report for the date being entered. However, now I need the Macro to input the day after today to the the day after today.
Example: If today is May 9, 2012 - the... (0 Replies)
Hi Guys
I have the following file
Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above:
Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
First, thanks for the help in previous posts... couldn't have gotten where I am now without it!
So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following:
If $1... (4 Replies)
Hi, all
I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes.
sample input:
for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Hi,
I have a comma delimited file that contains name, account number, and account date/time(example record below). I want to pull off all the records that have an account date greater than 8/1 of the current year, and create a new file with those records. So for this year, it would take... (6 Replies)
I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this:
abc ||| 5e-05 ||| bla
abc ||| 3 ||| ble
def ||| 1 ||| abc
def ||| 0.2 ||| def
As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)