LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-08-2007, 02:43 PM   #1
talat
Member
 
Registered: Jan 2006
Distribution: Centos
Posts: 145

Rep: Reputation: 16
Question 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
 
Old 09-08-2007, 03:43 PM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
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
 
Old 09-08-2007, 03:56 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
egrep -o "resp=.*" file > newfile

Cheers,
Tink
 
Old 09-08-2007, 08:59 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
put in some effort next time.
Code:
# awk '{print $NF}' file
resp=hsdakhhsd87e734hkdh387374
 
Old 09-08-2007, 11:20 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
As much to type as my solution, and quite likely slower.



Cheers,
Tink
 
Old 09-09-2007, 01:12 AM   #6
talat
Member
 
Registered: Jan 2006
Distribution: Centos
Posts: 145

Original Poster
Rep: Reputation: 16
Many Thanks guys
 
Old 09-10-2007, 11:16 AM   #7
talat
Member
 
Registered: Jan 2006
Distribution: Centos
Posts: 145

Original Poster
Rep: Reputation: 16
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
 
Old 09-10-2007, 01:25 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 09-10-2007, 06:53 PM   #9
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Tinkster View Post
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.
 
Old 09-10-2007, 07:18 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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



Cheers,
Tink
 
Old 09-10-2007, 08:49 PM   #11
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Tinkster View Post
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?
 
Old 09-10-2007, 10:08 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by ghostdog74 View Post
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
 
Old 09-11-2007, 03:33 AM   #13
talat
Member
 
Registered: Jan 2006
Distribution: Centos
Posts: 145

Original Poster
Rep: Reputation: 16
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ls -> Column Order daletaylor Linux - Newbie 3 06-22-2007 10:59 AM
ls column description anjanesh Linux - Newbie 5 01-04-2006 04:45 AM
add id in the first column alaios Linux - General 1 11-19-2004 06:49 AM
Column limit agallant Programming 1 08-05-2004 10:58 AM
add new column Eddie9 Linux - General 2 04-09-2002 12:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration