Hi,
I have a file with a long string, in the format:
name1=value,name2=value2.....namen=valuen
I want to query the file and extract 'value2' ONLY. name2=value2 can exist anywhere within the file.
Can anyone help me please wth a suitable BASH command?
Many thanks,
Matt
zaxxon
September 24, 2009, 10:02am
2
sed 's/.*name2=\(value2\).*/\1/g' infile
Thanks for that,
I didn't make it clear, the value is not fixed and can vary in length, however, 'name3' IS known and fixed
zaxxon
September 24, 2009, 10:20am
4
Np,
sed 's/.*name2=\([^=,]*\),.*/\1/g'
jp2542a
September 25, 2009, 1:01am
5
Off the cuff awk script:
/name2=/ {
recs = split($0, a, ",")
for ( i=1; i<=recs; i++)
{
if( a ~ /name2=/ )
{
print substr(a,7)
}
}
}