Can we do exact awk in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can we do exact awk in shell script
# 1  
Old 09-30-2011
Can we do exact awk in shell script

Hi,
I have three strings:

BusinessService=one
BusinessService1=two
BusinessService_test=three

If I user awk command, the out put will be all these. Actually am searching for "BusinessService" only.
Can we do exact awk command.
And the same tiem ,I cant user grep also. Because i need to print some column from the string.

Ex:
If i search "BusinessService" I need to print "one"
"BusinessService_test" --> Print "three".. Like that.

Please help on this....

Thanks,
Chelladurai.
# 2  
Old 09-30-2011
put all your strings in file called A, then run this :

Code:
root@linux [~]# cat A |grep BusinessService= |awk -F"=" '{print $2}'
one
root@linux [~]#

you can use this bash script to do it without you need to write all these commands each time:

Code:
#!/bin/bash
file=$1
search=$2
grep $2= $file |awk -F"=" '{print $2}'

then use it like this:

Code:
root@linux [~]# ./searchscript stringsfile BusinessService_test
three
root@linux [~]#

# 3  
Old 09-30-2011
Code:
$ awk -F= '/BusinessService=/ {print $2}' infile
one

# 4  
Old 09-30-2011
Hi, thanks for you reply..

This is my code:
rm newnames.txt
cd ear;
count=`ls *.ear |wc -l`
echo "Count is : $count"
ls *.ear |cut -d "." -f1>ear_names.txt
mv ear_names.txt ./../
cd ..
while read line
do
echo "val1:"$line
grep $line= names.txt >>newnames.txt
grep $line= | awk -F"=" '{print $2}' newnames.txt>>chells.txt
#tempvar1=`awk -F"=" '{print $2}' newnames.txt`:wq
echo "$tempvar1"
done<ear_names.txt


this is the filenames and content:
names:
BillingManagementServices_tst1=cow
BillingManagementServices_tst=peacock
BillingManagementServices=dog
ear_names:
BillingManagementServices_tst1
BillingManagementServices_tst
newnames:
BillingManagementServices_tst1=cow.


I have tried with the syntax. But its working for first iteration only. Not second and third..

Thanks
Chelladurai.
# 5  
Old 09-30-2011
you have syntax error inside this line :

Code:
 grep $line= | awk -F"=" '{print $2}' newnames.txt>>chells.txt

you need to change it to :

Code:
grep $line= newnames.txt | awk -F"=" '{print $2}' >>chells.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vlookup using awk without exact match

Code used to find the server from cloum 3 and update needtotakesnap Output came from above command awk 'NR==FNR{A;next}$3 in A{$3 = "needtotakesnap " $3}1' /home/Others/active-server.txt /home/Others/all-server |grep server1 879 dummy server1_217_silver dummy 00870 TDEV 2071575 831 Tier1... (3 Replies)
Discussion started by: ranjancom2000
3 Replies

2. Shell Programming and Scripting

To split a file in exact half using awk

file: 1 2 3 4 5 6 7 8 9 10 code: awk 'END{if( < NR/2) {print $0}}' file The above has some error Output needed: (8 Replies)
Discussion started by: Roozo
8 Replies

3. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

4. Shell Programming and Scripting

How to get the exact word in awk?

Hi, i have a file that contains the following: ARTPRD01_app = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 11.222.3.4)(PORT = 1540)) (CONNECT_DATA = (SERVICE_NAME = artprd01.com) ARTPRD01 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 11.223.3.1)(PORT =... (2 Replies)
Discussion started by: reignangel2003
2 Replies

5. Shell Programming and Scripting

echo exact xml tag from an exact file

Im stumped on this one. Id like to echo into a .txt file all names for an xml feed in a huge folder. Can that be done?? Id need to echo <name>This name</name> in client.xml files. $path="/mnt/windows/path" echo 'recording names' cd "$path" for names in $path than Im stuck on... (2 Replies)
Discussion started by: graphicsman
2 Replies

6. Shell Programming and Scripting

Match exact Variable in Awk

I want to match exact string stored in Variable INO and print next two lines. I have written below code which partially matches: awk '/\'$VAR'/{getline; getline; print}' Will be thankful , if somebody can help in to resolve this problem. Please view this code tag video for how to use... (9 Replies)
Discussion started by: nitj
9 Replies

7. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

8. Shell Programming and Scripting

Exact Search and Replace using AWK

Hello. I have written the following script to search and replace from one file into another. #awk script to search and replace from file a in file b NR == FNR { A=$2; next } { for( a in A ) sub(a, A)}1 file2 file1 While the function works pretty well, I want a. The word in File 2 to... (8 Replies)
Discussion started by: gimley
8 Replies

9. Shell Programming and Scripting

awk to print exact field number

Hello there. I want some help with awk I have this script that reads a file from awk and you can insert from keyboard any list from the fields that exist so to be printed on monitor echo "give a choice" read -a ans array=${ans} awk -F: -v k="$array" '{ ... (4 Replies)
Discussion started by: covis
4 Replies

10. Shell Programming and Scripting

AWK seach for exact word in certain column

Can anyone help me how I will extract all lines in a file where the word "worker" or "co-worker" in 2nd column exist. There are also word in 2nd column like "workers" or "worker2" but I don't want to display those lines. Appreciate any help in advance! Thank you! (5 Replies)
Discussion started by: Orbix
5 Replies
Login or Register to Ask a Question