LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Extracting particular column value (https://www.linuxquestions.org/questions/programming-9/extracting-particular-column-value-583207/)

talat 09-08-2007 02:43 PM

Extracting particular column value
 
HI Guys

I need little help.Consider that i have a file which contain multiple lines
.In each line there is one particular field which has some value.I just want to extract that value and place that in a new file.The example of the line is given below





service: month day time info: somethink : client in something 1 staright service=something secured ip=8990000 ip=989898 resp=hsdakhhsd87e734hkdh387374


This whole is in one line and the value i want to fetch is of resp.

Please guide me

Regard
Talat

gnashley 09-08-2007 03:43 PM

Something like this should work:
Code:

while read line ;
for word in $line ; do
if [[ "$(echo $word |cut -f1 -d=)" = "resp" ]] ; then
 value_wanted="$(echo $word |cut -f2- -d=)
fi

do < filename.txt


Tinkster 09-08-2007 03:56 PM

Code:

egrep -o "resp=.*" file > newfile

Cheers,
Tink

ghostdog74 09-08-2007 08:59 PM

put in some effort next time.
Code:

# awk '{print $NF}' file
resp=hsdakhhsd87e734hkdh387374


Tinkster 09-08-2007 11:20 PM

As much to type as my solution, and quite likely slower.



Cheers,
Tink

talat 09-09-2007 01:12 AM

Many Thanks guys

talat 09-10-2007 11:16 AM

Hi Guys

After extracting the resp value and placing the value in another file, i am now trying to decode the value by mmencode tool.But when i run the cmd

mmencode -u file -o output file

What i get in the output file is the decoded value of only first line or you can say only one decode value .Tell me is this mmencode run only for the first line ?. If yes do i have any alternative ?.

Regard
Talat

Tinkster 09-10-2007 01:25 PM

I've never come across mmencode ... what does it do? If it
can't handle your file, throw the content at it via xargs?


cat file2 | xargs -i mmencode ...{}

Where {} is a placeholder for each individual line from the
file that you created in the first step.




Cheers,
Tink

ghostdog74 09-10-2007 06:53 PM

Quote:

Originally Posted by Tinkster (Post 2887744)
I've never come across mmencode ... what does it do? If it
can't handle your file, throw the content at it via xargs?


cat file2 | xargs -i mmencode ...{}

Where {} is a placeholder for each individual line from the
file that you created in the first step.




Cheers,
Tink

Correct me if i am wrong, xargs have an option -a (--arg-file=file) so i think there's no need for cat.

Tinkster 09-10-2007 07:18 PM

That'll depend on the version of xargs... the ones in Solaris for
instance don't.



Cheers,
Tink

ghostdog74 09-10-2007 08:49 PM

Quote:

Originally Posted by Tinkster (Post 2888061)
That'll depend on the version of xargs... the ones in Solaris for
instance don't.
Cheers,
Tink

yup, that's true. btw, the -o option of egrep is not available in the Solaris version..or does it?

Tinkster 09-10-2007 10:08 PM

Quote:

Originally Posted by ghostdog74 (Post 2888137)
yup, that's true. btw, the -o option of egrep is not available in the Solaris version..or does it?


Which one? :}

The /usr/bin/egrep doesn't.
The /usr/sfw/bin/gegrep does in Sol10, doesn't in Sol9...



Cheers,
Tink

talat 09-11-2007 03:33 AM

Hi Guys

I have been able to decode all line via

while read line; do echo $line | /usr/bin/mimencode -u >> outputfile; echo "\n" >> outputfile ; done < inputfile


Thanks & Regard
Talat


All times are GMT -5. The time now is 06:01 AM.