LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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,752

Rep: Reputation: 462Reputation: 462Reputation: 462Reputation: 462Reputation: 462
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: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

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

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

Rep: Reputation: 241Reputation: 241Reputation: 241
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: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
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: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
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: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 10:32 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration