LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-14-2009, 09:27 PM   #1
wjs1990
Member
 
Registered: Nov 2009
Posts: 30

Rep: Reputation: 15
Need help on grep command


Hi all,
For example, i have two similar line "net.ipv4.tcp_syncookies = 1" and "net.ipv4.tcp_syncookies =1". The difference is just that one of them have space between the "=" and "1", and the other one does not have.
Then i used, the command " grep -v "^#" /etc/sysctl.conf | grep -w net.ipv4.tcp_syncookies | awk -F= '{print $2}' ". The results i get will be " 1" and "1" for the two lines respectively.
So, does anyone have any idea on how can i get the result "1" for both lines, using the same command.

Thanks
 
Old 12-14-2009, 09:35 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
just one awk command will do
Code:
awk -F'= ' '!/^#/&&/net.*ipv4.*tcp_syncookies/{print $2}' /etc/sysctl.conf
or using the shell
Code:
while read -r line
do
    case "$line" in
       net.ipv4.tcp_syncookies*)
       IFS="="
       set -- $line
       echo ${2// }
    esac
done <"/etc/sysctl.conf"

Last edited by ghostdog74; 12-14-2009 at 10:59 PM.
 
Old 12-14-2009, 09:59 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Code:
sed -nr 's:(net.ipv[^=]*=)(.*):\2:p' /etc/sysctl.conf
 
  


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
grep command john83reuben Linux - Newbie 9 12-09-2009 11:21 AM
How to pass the result of a command to another command (like grep) desb01 Programming 4 06-25-2009 12:09 PM
using grep command hiteshthappa Linux - Newbie 4 07-11-2008 08:34 AM
Help me in Grep Command + cd command in single line JeiPrakash Linux - Newbie 3 05-27-2008 04:16 AM
using grep command mruknown1 Linux - Newbie 11 09-11-2007 11:06 AM

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

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