在指定的文件过滤想要的内容

通过内容进行过滤

grep 关键字 文件名

如下:

[root@source ~]# cat anaconda-ks.cfg 
# Kickstart file automatically generated by anaconda.


#version=DEVEL
install
cdrom
lang en_US.UTF-8
keyboard us
network --onboot no --device eth0 --bootproto dhcp --noipv6
rootpw  --iscrypted $6$JvEQdLOWpZU1/bvT$sukU9N3tBoZMhCVkNvJSaJ1TEJaSqFOzY6AiD3XoGosQ4QuY0ZHm6g7Vqw7Ena6VO24yLH/eN7yzIbRXk3GsG0
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --linux --drives=sda


#part /boot --fstype=ext4 --size=500
#part pv.008002 --grow --size=1


#volgroup vg_source --pesize=4096 pv.008002
#logvol / --fstype=ext4 --name=lv_root --vgname=vg_source --grow --size=1024 --maxsize=51200
#logvol swap --name=lv_swap --vgname=vg_source --grow --size=4000 --maxsize=4000




%packages
@additional-devel
@backup-client
@backup-server
@base
@cifs-file-server
@client-mgmt-tools
@compat-libraries
@console-internet
@core
@debugging
@basic-desktop
@desktop-debugging
@desktop-platform
@desktop-platform-devel
@development
@dial-up
@directory-client
@directory-server
@mail-server
@eclipse
@emacs
@storage-client-fcoe
@ftp-server
@fonts
@general-desktop
@graphical-admin-tools
@graphics
@hardware-monitoring
@identity-management-server
@infiniband
@input-methods
@internet-browser
@java-platform
@kde-desktop
@large-systems
@legacy-unix
@legacy-x
@mainframe-access
@system-management-messaging-client
@mysql-client
@mysql
@nfs-file-server
@network-server
@storage-server
@network-file-system-client
@network-tools
@php
@performance
@perl-runtime
@postgresql-client
@postgresql
@print-server
@print-client
@remote-desktop-clients
@ruby-runtime
@system-management-snmp
@scientific
@security-tools
@server-platform
@server-platform-devel
@server-policy
@smart-card
@storage-client-multipath
@system-management
@system-admin-tools
@tex
@technical-writing
@turbogears
@virtualization
@virtualization-client
@virtualization-platform
@virtualization-tools
@web-server
@web-servlet
@system-management-wbem
@x11
@storage-client-iscsi
libXinerama-devel
openmotif-devel
libXmu-devel
xorg-x11-proto-devel
startup-notification-devel
libgnomeui-devel
libbonobo-devel
junit
libXau-devel
libgcrypt-devel
popt-devel
gnome-python2-desktop
libdrm-devel
libXrandr-devel
libxslt-devel
libglade2-devel
gnutls-devel
mtools
pax
python-dmidecode
oddjob
wodim
sgpio
genisoimage
device-mapper-persistent-data
systemtap-client
abrt-gui
qt-mysql
desktop-file-utils
ant
rpmdevtools
jpackage-utils
rpmlint
samba-winbind
certmonger
openldap-clients
pam_krb5
krb5-workstation
ldapjdk
samba
krb5-server
netpbm-progs
ImageMagick
slapi-nis
tcp_wrappers
openmotif
xterm
xorg-x11-xdm
libXmu
libXp
python-saslwrapper
perl-DBD-MySQL
dnsmasq
radvd
ebtables
sg3_utils
perl-DBD-SQLite
perl-Mozilla-LDAP
rdesktop
atlas
compat-openmpi
numpy
compat-openmpi-psm
p11-kit-trust
hmaccalc
crypto-utils
scrub
libvirt-java
mod_auth_kerb
mod_nss
certmonger
perl-CGI
python-memcached
mod_revocator
memcached
%end[root@source ~]# grep mod_nss anaconda-ks.cfg 
mod_nss


过滤指定行:

[oracle@source ~]$ cat .bash_profile 
# .bash_profile


# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi


# User specific environment and startup programs


PATH=$PATH:$HOME/bin


export PATH




export EDITOR=vi
export ORACLE_SID=test
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin
umask 022
[oracle@source ~]$ sed -n 1p  .bash_profile 
# .bash_profile

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29802484/viewspace-2114772/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29802484/viewspace-2114772/

你可能感兴趣的:(在指定的文件过滤想要的内容)