Why does this work:
Code:
awk -v s="this is a string" 'index($0, s)' file
while the following doesn't?
Code:
s="this is a string"
awk -v s=$s 'index($0, s)' file
How do I search for a string with spaces in it?
---------- Post updated at 01:18 AM ---------- Previous update was at 01:15 AM ----------
I figured it out.
i would like to search for a letter in a string and get its index position.
example:
Code:
name='john'
pos=$(expr index $name o)
the result will be equal to 2 (2nd position)
how do you make this thing not case sensitive?
example:
Code:
name='john'
pos=$(expr index $name O)
the capitalization is the issue.
Moderator's Comments:
Why does this work:
Code:
awk -v s="this is a string" 'index($0, s)' file
while the following doesn't?
Code:
s="this is a string"
awk -v s=$s 'index($0, s)' file
How do I search for a string with spaces in it?
---------- Post updated at 01:18 AM ---------- Previous update was at 01:15 AM ----------
I figured it out.
I cannot correctly write the generic method for this:
private int [] loadIntArray(String key, int [] defaultArray) {
int [] array = new int [4];
for( int index=0; index<4 ; index++) {
array[index] = sp.getInt(key + index, defaultArray[index]);
}
return array;
}
I wrote this:
private <T[]> loadArray(String key, <T[]> defaultArray) {
<T[]> array =
hi
i have a requirement to input a string to a shell script and to split the string to multiple fields,
the string is copied from a row of three columns (name,age,address) in an excel sheet.
the three columns (from excel) are seperated with a tab when pasted in the command prompt, but when the
string is assigned to a variable, the tab disappears to a space.
code is given below
Code:
echo
When I search for the string
Code:
capId=...
using
Code:
awk '/capId=.../' file
I get successful results.
However when I feed the string as a variable, like this:
Code:
str="capId=..."
awk -v str="$str" 'index($0, str)' file
I get no results.
What can I do if I need to generate a string that contains wildcards and feed it to awk?
I am really new to bash scripting, and I can not figure it out how to do this. I have string which is an output of another command. I only need the end of this string to display. The separator string is ". " (dot and space), and I need the string after the last index of ". "
It would be easy in other languages for me, but I do not know how to do this basic operation in bash.
I'm new to gawk. I read the asort function sorts by data element values; when no sort function is specified, in the default order (which I took as numerical sort or lexicographic sort respectively).
Hi,
I have a list of urls in my input.txt file like this
input.txt
Code:
http://unix.com/index.html?acc=OSR765454&file=filename1.gz
http://unix.com/index.html?acc=OBR765454&file=filename111.gz
http://unix.com/index.html?acc=ORS765454&file=filename1111.gz
http://unix.com/index.html?acc=OST76454&file=filename11111.gz
http://unix.com/index.html?acc=OS5454&file=filename1111