Visit Our UNIX and Linux User Community


want to pattern match using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting want to pattern match using awk
# 1  
Old 08-06-2009
want to pattern match using awk

Hello Friends,

My script gives an output like below:- but i only want the red part to be displayed. how to i do that. I am enclosing my shell script after that.

id='CCRCWebServerINSTALLDIR'
id='AdministrationTools-CINSTALLDIR'
id='AdministrationTools-ent-CINSTALLDIR'
id='AlbdServer-CINSTALLDIR'
id='Integration-CINSTALLDIR'
id='ClientComponentsINSTALLDIR'
id='Converters-CINSTALLDIR'
id='CoreComponents-CINSTALLDIR'
id='DotNetClient'
id='ExplorerIntegration-CINSTALLDIR'
*****************************************************
The acutal output

id='CCRCWebServerINSTALLDIR'
id='AdministrationTools-CINSTALLDIR'
id='AdministrationTools-ent-CINSTALLDIR'
id='AlbdServer-CINSTALLDIR'
id='Integration-CINSTALLDIR'
id='ClientComponentsINSTALLDIR'
id='Converters-CINSTALLDIR'
id='CoreComponents-CINSTALLDIR'
id='DotNetClient'
id='ExplorerIntegration-CINSTALLDIR'

************************************************8
Script
#!/bin/sh

ECHO=/bin/echo
CAT=/bin/cat
LS=/bin/ls
AWK=/bin/awk
GREP=/bin/grep

FIX_XML_PATH=/home/administrator/testfix/fix
FIX_FILE=`$LS $FIX_XML_PATH | $GREP xml`

#$ECHO $FIX_FILE
$CAT $FIX_XML_PATH/$FIX_FILE | $GREP id | $AWK '{if($2 ~ /id=/) print $2}'
# 2  
Old 08-06-2009
Try :
Code:
awk -F"'" '$1 == "id=" {print $2}' $FIX_XML_PATH/$FIX_FILE'

Jean-Pierre.
# 3  
Old 08-06-2009
Or you can remove them by piping your awk output to sed (more generic if you're input doesn't always start with "id="):

Code:
$AWK ..... | $SED "s/'//g"

(don't forget to define SED=/bin/sed!)
# 4  
Old 08-06-2009
Thanks that worked.

-Adi

Previous Thread | Next Thread
Test Your Knowledge in Computers #903
Difficulty: Medium
There are less than 10 million lines of code in the Linux kernel as of 2018.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filesystem pattern match in awk

Hi, I'm trying to grep appln processes using its filesystem and also using awk to get accurate results, however when i'm uisng the filesystem in awk statement i'm getting error. Requesting help. ps -eaf | grep ApplnName | awk '/ /opt/xxx/yyy / { print }' Trying with this above code; getting... (7 Replies)
Discussion started by: sam_bd
7 Replies

2. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

3. Shell Programming and Scripting

awk Pattern Match One File to Another

I want to read from file 1 and pattern match in file two and print field two from the next line. File 1: user1 user2 user3 File 2: name=user1 gud=12345 name=user2 gud=32456 I have this pattern hardcoded but can't work out how to pass file 1 to the pattern match: (6 Replies)
Discussion started by: u20sr
6 Replies

4. Shell Programming and Scripting

Awk to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

5. Shell Programming and Scripting

sum using awk with pattern match

I have a file which has data like this *** Query completed. One row found. *** Query completed. One row found. *** Query completed. One row found. *** Insert completed. 5 rows added. *** Query completed. No rows found. *** Query completed. One row found. *** Query completed. One... (2 Replies)
Discussion started by: sol_nov
2 Replies

6. Shell Programming and Scripting

AWK match $1 $2 pattern in file 1 to $1 $2 pattern in file2

Hi, I have 2 files that I have modified to basically match each other, however I want to determine what (if any) line in file 1 does not exist in file 2. I need to match column $1 and $2 as a single string in file1 to $1 and $2 in file2 as these two columns create a match. I'm stuck in an AWK... (9 Replies)
Discussion started by: right_coaster
9 Replies

7. UNIX for Dummies Questions & Answers

awk -repeated pattern match

Hi. How can I write this differently: awk '$3 ~ /0001/{print}' Is there a way to write 0001 differently. I am looking for the pattern 01, with 3 or more 0 and 3 or more 1 in a pattern. Thanks. (12 Replies)
Discussion started by: danieladna
12 Replies

8. Shell Programming and Scripting

Awk match a multiline pattern

Hello! i wanna match in a config file, one text with more than one lines, something like this: CACHE_SIZE{ 10000 M } I have problems with the ends of line, i think that i can match the end of the line with \n, but i can't get it Someone can help me with the regular expression? ... (18 Replies)
Discussion started by: claw82
18 Replies

9. Shell Programming and Scripting

Use to awk to match pattern, and print the pattern

Hi, I know how to use awk to search some expressions like five consecutive numbers, , this is easy. However, how do I make awk print the pattern that is been matched? For example: input: usa,canada99292,japan222,france59664,egypt223 output:99292,59664 (6 Replies)
Discussion started by: grossgermany
6 Replies

10. Shell Programming and Scripting

how do i pattern match a field with awk?

hi, let's say $numbers = "324 350 587" an so on... what i'm trying to do is this: awk -v numbers="$numbers" '{if (numbers ~ /$2/) print $0, "bla bla"}' file # file looks like this: 214 ..... 215 ... 216 .... 250 ... 324 325 ... 350 something ... ... 587 ... (4 Replies)
Discussion started by: someone123
4 Replies

Featured Tech Videos