LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-28-2011, 06:04 AM   #1
ameylimaye
LQ Newbie
 
Registered: Aug 2011
Posts: 25

Rep: Reputation: Disabled
how do i grab the data in a line?


HI,
I am not able to grab the characters in a line..
for example

i have a line

"Subnetwork=1020,ManagedElement=1,moextent=BAD001,AntennaSector=B "

in this i have to grab the characters "BAD001"

what should i do? can any one help me please?
 
Old 09-28-2011, 06:11 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Using awk you can do something like this:
Code:
$ line='"Subnetwork=1020,ManagedElement=1,moextent=BAD001,AntennaSector=B "'
$ field=$(echo $line | awk 'BEGIN{FS="=";RS=","}/moextent/{print $NF}')
$ echo $field
BAD001
 
Old 09-28-2011, 06:31 AM   #3
snooly
Member
 
Registered: Sep 2011
Posts: 124

Rep: Reputation: Disabled
Suppose your file is called abc.txt, you can use the "cut" command twice like this:

cut -d = -f 4 abc.txt | cut -d , -f 1

As you will learn when you read "man cut", the -d switch sets the delimiter character, and -f indicates which field you want.
 
Old 09-28-2011, 06:54 AM   #4
ameylimaye
LQ Newbie
 
Registered: Aug 2011
Posts: 25

Original Poster
Rep: Reputation: Disabled
thank you
 
  


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
[SOLVED] Grab line based on string DuskFall Linux - Newbie 3 08-09-2011 03:08 PM
How to grab certain data from trace file? yida Linux - Newbie 16 08-03-2010 05:49 PM
How to grab certain data from trace file? yida Linux - Networking 2 07-31-2010 07:20 AM
Filter through line/s to grab specific fields/data in the line with example shayno90 Linux - Newbie 11 10-14-2009 12:51 PM
grab the line below a blank line and the line above the next blank line awk or perl? Pantomime Linux - General 7 06-26-2008 09:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration