Calling of search using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling of search using awk
# 1  
Old 01-24-2010
Calling of search using awk

Code:
Database
rina lives:fatin:20:20:20
rina:fatin:20:20:20

i am having a small problem in extracting out the information from the database. For example, if i were to input a book titled rina into my search , i would only want it to display the row which has the title rina, like this

Code:
rina:fatin:20:20:20

but when i use a coding like this :
Code:
grep -i "$Title" fruit| awk -F":" '{ print $0}'`

its displays both titles and their information

Code:
rina lives:fatin:20:20:20
rina:fatin:20:20:20

for some reason, it will read both rows as both contains the word "rina". does anybody know how i can modify my statement to solve this problem?
# 2  
Old 01-24-2010
Try:
Code:
grep -i "^$Title:" fruit

# 3  
Old 01-24-2010
hey thanks. could you help explain what ^ means?
# 4  
Old 01-24-2010
Code:
awk -F: '$1==str' str="${Title}" OFS=':' fruit

# 5  
Old 01-24-2010
Quote:
Originally Posted by gregarion
hey thanks. could you help explain what ^ means?
It is called and anchor. It limits the match to what is at the begin of the line.

@vgersh99. I think OFS is superfluous in this case, no?:
Code:
awk -F: '$1==str' str="$Title" fruit

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Calling all the awk gurus out there.

Hi all, I just signed up to the forums, although, I have lurked on here for awhile. Anyways, my issue is I am trying to get awk to spit out something I can use without having to spend hours in excel hell haha. So, I used sed to replace the spaces with semicolons and redirected that to a file. ... (6 Replies)
Discussion started by: savigabi
6 Replies

2. Shell Programming and Scripting

Calling array inside awk

Hello I have the file df.tmp FS is actually the / FS but escape character\ and end of line $ is used in order to fetch exctly / and not other filesystems. awk '/\/$/ {print $(NF-1)+0}' df.tmp will work properly and return a value eg. 60 but when I am trying to issue the command with the array... (3 Replies)
Discussion started by: drbiloukos
3 Replies

3. Shell Programming and Scripting

calling awk from php not working

I want to run awk from php to do some text processing. I am giving an extremely simple example below: onecol.awk file ------------------- { print "Hello!"; } f1.txt --------- aaa ccc eee f2.txt --------- (6 Replies)
Discussion started by: mary271
6 Replies

4. Shell Programming and Scripting

Calling awk fom csh

I have to call two awk scripts where the second one used the output from the first one. Am wondering if it may happen that the second awk might start before the first awk finished creating the file... if ($nAnomaly == 1) then awk -v anomaly=$Anom -v zloc="$zmin/$zmax" -v dz=$dz \ ... (1 Reply)
Discussion started by: kristinu
1 Replies

5. Shell Programming and Scripting

Calling awk from csh

I am trying to call awk from a csh script using awk '{print $1, -$2, $3}' $fvmod.vel > $fvmod.xzv and getting awk: Command not found. Running awk '{print $1, -$2, $3}' $fvmod.vel > $fvmod.xzv on the command line with the actual filenames works (2 Replies)
Discussion started by: kristinu
2 Replies

6. Shell Programming and Scripting

Calling function in awk statement.

Hi All, I have an awk statement and a function defined in a script. I am trying to call the function from inside awk statement, i.e. awk ' myFunk () ;' filename But when I define myFunk() before awk, then I receive this error: s2.sh: line 48: syntax error: unexpected end of file and... (5 Replies)
Discussion started by: morningSunshine
5 Replies

7. Shell Programming and Scripting

calling a method inside awk

Hi All, How do we call a method existing in another file inside awk. After matching a pattern i want to call a method secureCopy that exists in another file, but method not getting called: ls -l | awk -v var2=$servername -v var1=$srcserverpath -v var3=$tgtpath '... (1 Reply)
Discussion started by: abhinav192
1 Replies

8. Solaris

calling script from awk

Hi, I'm not sure, there is solution exist for this problem. I'm facing problem in calling a unix script from awk code. Here is code nawk -F'=' ' BEGIN { } function runtest(string) { LINE } /^/ { # getting module name t=$1 module=substr(t,2,(length(t)-2)) runtest(module) }... (1 Reply)
Discussion started by: luckybalaji
1 Replies

9. Shell Programming and Scripting

calling function inside awk

Hi All, My 1.txt contains some functions fun1() .... .... fun2() .... .... I can call these fun from 2.txt inside awk as below value="`fun1 "argument1"`" awk 'BEGIN {printf ("%s", "'"$value"'")}' I need to modify the above code so that without using the variable to store... (2 Replies)
Discussion started by: jisha
2 Replies

10. Shell Programming and Scripting

Calling ipcrm from awk

Hello, With next simple command line I get all allocated semaphore numbers: ipcs -s | awk 'NR > 3 {print $2}' Now I want to add ipcrm -s before each semaphore id and actually delete every last of them. The question is: Can I do the operation in a command itself, without redirecting awk... (2 Replies)
Discussion started by: BaruchLi
2 Replies
Login or Register to Ask a Question