LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-22-2005, 02:25 PM   #1
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Rep: Reputation: 15
retrievin a certain piece of text


i want a command that will get the port number without spaces and put it into a variable string so i can use it in another script is there a command that will grab the port number say look through the file and grab what ever is between port and +set

but also remove the space from front and end of it



./mohaa_lnxded +ip 217.146.92.89 +set net_port 14200 +set sv_maxclients 12 +set fs_basepath ./ +set fs_outputpath ./logs +set com_zoneMegs 30 +set vm_game 0 +set ttycon 0 +set dedicated 1 +set developer 2 +set logfile 3 +set g_logsync 1 +set chat 1 +set chatter 1 +exec server.cfg

sorry for asking so many questions but i love linux now and want to learn fast

thanks in advance
 
Old 11-22-2005, 03:56 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,985
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Code:
sed -e 's@\(.*port \([0-9]*\) +.*\)@\2@g' filename


Cheers,
Tink
 
Old 11-22-2005, 04:23 PM   #3
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Original Poster
Rep: Reputation: 15
Code:
sed -e 's@\(.*port \([0-9]*\) +.*\)@\2@g' filename
that actually diplays the whole file but on the line with port all it displays is the port example below

#! /bin/bash

function savelog
{
echo saving log
DATE=$(date +%Y%m%d%H%M)
LOGSAVE=qconsole-$DATE.log

# ensure file does not exist
while [ -e $LOGSAVE ]; do
DATE=$DATE1
LOGSAVE=qconsole-$DATE.log
done
echo moving $LOGDIR/qconsole.log to $LOGDIR/$LOGSAVE
mv $LOGDIR/qconsole.log $LOGDIR/$LOGSAVE
}

LOGDIR=logs/main

touch loop

if [ -e $LOGDIR/qconsole.log ]; then
savelog;
fi

while [ -e loop ]; do

14200

savelog
done

so as you can see it got rid of the info around it but how can i get rid of rest and just keep that number
 
Old 11-22-2005, 05:41 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,985
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Not sure what your problem is, here it does exactly that.
Code:
$ cat blah.txt
./mohaa_lnxded +ip 217.146.92.89 +set net_port 14200 +set sv_maxclients 12 +set fs_basepath ./ +set fs_outputpath ./logs +set com_zoneMegs 30 +set vm_game 0 +set ttycon 0 +set dedicated 1 +set developer 2 +set logfile 3 +set g_logsync 1 +set chat 1 +set chatter 1 +exec server.cfg
./mohaa_lnxded +ip 217.146.92.89 +set net_port 1200 +set sv_maxclients 12 +set fs_basepath ./ +set fs_outputpath ./logs +set com_zoneMegs 30 +set vm_game 0 +set ttycon 0 +set dedicated 1 +set developer 2 +set logfile 3 +set g_logsync 1 +set chat 1 +set chatter 1 +exec server.cfg
./mohaa_lnxded +ip 217.146.92.89 +set net_port 4200 +set sv_maxclients 12 +set fs_basepath ./ +set fs_outputpath ./logs +set com_zoneMegs 30 +set vm_game 0 +set ttycon 0 +set dedicated 1 +set developer 2 +set logfile 3 +set g_logsync 1 +set chat 1 +set chatter 1 +exec server.cfg
Code:
$ sed -e 's@\(.*port \([0-9]*\) +.*\)@\2@g' blah.txt 
14200
1200
4200

[edit]
Oic ... you mean there's lines in the file that don't have
any "port" in them, and those then would be displayed.

To fix that just do
Code:
awk '/port/' filename | sed -e 's@\(.*port \([0-9]*\) +.*\)@\2@g'
[/edit]



Cheers,
Tink

Last edited by Tinkster; 11-22-2005 at 06:09 PM.
 
  


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
Chess Piece Icons ninjabob7 Programming 5 11-24-2005 12:51 PM
How to cut a piece of my partition? don_dimo Linux - Hardware 2 05-30-2005 10:13 AM
How do I isolate a piece of string? vous Programming 4 03-16-2005 01:43 PM
Looking for a piece of software jkruer01 Linux - Software 5 07-23-2004 03:52 PM
what is this funny piece of hardware? andzerger Linux - Hardware 3 03-10-2004 10:33 PM


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