![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Match words | moutaz1983 | Shell Programming and Scripting | 8 | 01-07-2008 03:26 AM |
| Dynamic SQl in KSH | kousikan | Shell Programming and Scripting | 2 | 03-18-2007 09:12 AM |
| how to dynamic DNS | bondoq | Linux | 1 | 11-14-2006 07:34 AM |
| Dynamic DNS | [MA]Flying_Meat | OS X (Apple) | 0 | 12-06-2005 06:07 PM |
| dynamic pid? | yls177 | UNIX for Dummies Questions & Answers | 2 | 12-17-2002 05:26 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
dynamic match thru awk
hey ,
my i/p text looks like this, FILE_TYPE=01|FILE_DESC=Periodic|FILE_SCHDL_TYPE=Daily|FILE_SCHDL=|FILE_SCHDL_TIME=9:00am|RESULTS=B FILE_TYPE=02|FILE_DESC=NCTO|FILE_SCHDL_TYPE=Daily|FILE_SCHDL=|FILE_SCHDL_TIME=9:00am|RESULTS=M NOTE Look carefully for the position FILE_TYPE,FILE_DESC etecetra etcetra this position may varry, e.g. FILE_TYPE is here in 1st postion might be to-morrow in the 3rd or last postion, So my query is to give the input search name, and it should display the field value, FILE_TYPE and value after = . |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
awk -F"|" '/inputvalue/ { print $3 }' filename
|
|
#3
|
|||
|
|||
|
Give a try,
Code:
#! /usr/bin/perl
$inpFile=$ARGV[0];
$searchStr=$ARGV[1];
open (INP,"<$inpFile") || die "Unable to open INPFILE::$inpFile\n";
while (<INP>) {
$_ =~ s/\x0a|\x0d//g;
@inpTag = split(/\|/,$_);
foreach $value ( @inpTag ) {
($key,$val) = (split ( /=/,$value ));
if ( $key =~ /\b$searchStr\b/ ) {
print "$key= $val\n";
}
}
}
close (INP);
|
|
#4
|
||||
|
||||
|
hey matrixmadhan, Field is not static, it might be changed across the file.
so according to the i/p search value, i want to fetch the field name and value . hey lorcan , thanx a lot..can i have this in unix...not thru perl. |
|
#5
|
|||
|
|||
|
Code:
cat your_file | tr "|" "\n" | grep -x "searchField=" Code:
tr "|" "\n" < your_file | grep -x "searchField=" |
|
#6
|
|||
|
|||
|
Quote:
code is this ; cat inputfile |awk -F'|' -v srchname=$1 ' $1 ~ srchname {print $1}; $2 ~ srchname {print $2};$3 ~ srchname {print $3};$4 ~ srchname {print $4}; $5 ~ srchname {print $5};$6 ~ srchname {print $6}' the first $1 is command line parameter comes from outside the script. so you can use your script this way from command line or call from an another program ; myscript FILE_TYPE or myscript FILE_DESC etc. Last edited by fazliturk; 08-17-2007 at 06:48 AM. |
|
#7
|
||||
|
||||
|
hey fazliturk,
thanx a lot...but if the field is going to change i.e. might be increased from 6 to 7 then , in real time it is not feasible to change the query to add one line $7 ~ srchname {print $7} !!!!!! So i want irrespective of all the changes to i/p file, that we can think of, it should give us the o/p of the proper search value....but anyway thanx a lot. lorcan, i tried your one it works fine , with some modification according to my requirement ....But still can we have some more modularized one...using AWK or SED. |
||||
| Google The UNIX and Linux Forums |