LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-02-2009, 09:44 PM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 37
Output formatting help needed.


Hi guys ,
I have a file which contains following string.(filename tempdisplay)
(location 0.0.0.0:5900)

i needed to write a script which will extract the string that comes after
0.0.0.0 i.e the string :5900.

I have used following method to extract the string :5900 .Is it a preferred way of doing the job?


sed s/"(location 0.0.0.0"/""/ tempdisplay > temp2display
#temp2display will now contain :5900)
temp=`sed s/")"/""/ temp2display`
#temp will now contain :5900
echo $temp

output:
:5900







Please help me with the syntax of the script.

Last edited by pinga123; 11-03-2009 at 12:43 AM.
 
Old 11-02-2009, 09:49 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
so what have you tried...?if you have not started to learn shell scripting yet, see my sig to learn bash.

Last edited by ghostdog74; 11-02-2009 at 09:51 PM.
 
Old 11-02-2009, 11:33 PM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by ghostdog74 View Post
so what have you tried...?if you have not started to learn shell scripting yet, see my sig to learn bash.
I m doing it using a sed program
but i think sed only takes input from a file.
but above mentioned string is a output of a command and i want the output should be formated according to my need.
can u help me out with this bro.
 
Old 11-03-2009, 12:57 AM   #4
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 37
Is there any better way of doing this.
 
Old 11-03-2009, 01:01 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,395

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
man cut
 
Old 11-03-2009, 01:04 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by pinga123 View Post
Is there any better way of doing this.
of course, one way
Code:
$ echo "(location 0.0.0.0:5900)" | awk -F":" '{print $NF}'
5900)
look at my sig for learning awk.
 
Old 11-03-2009, 02:50 AM   #7
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by ghostdog74 View Post
of course, one way
Code:
$ echo "(location 0.0.0.0:5900)" | awk -F":" '{print $NF}'
5900)
look at my sig for learning awk.
How can i remove ) from 5900) in just one line.
 
Old 11-03-2009, 03:00 AM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
use gsub() or sub(). i repeat again. please start reading the docs (see my sig)
 
Old 11-03-2009, 06:34 AM   #9
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 37
The simplest command that i have used is :grep -o ':[0-9]*' tempdisplay
 
  


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
formatting iostat output suran Linux - General 4 07-14-2009 07:00 AM
[SHELL] Output formatting Adrnalnrsh Programming 3 09-22-2008 10:29 AM
Formatting output krock923 Programming 2 06-07-2006 07:26 AM
formatting date output grob115 Linux - Newbie 2 01-28-2006 08:03 AM
Formatting output of ls doodar Linux - Newbie 29 07-29-2004 01:25 PM

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

All times are GMT -5. The time now is 09:24 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