xargs用法示例

实例文件内容:
----------------------------
# cat 1.log
 oraclelinux-release.x86_64 6:6Server-6.0.2                                                                               redhat-release-server.x86_64 1:6Server-6.6.0.2.0.1.el6                                                                              
  DeviceKit-power.x86_64 0:014-3.el6                               NetworkManager.x86_64 1:0.8.1-75.el6                          NetworkManager-gnome.x86_64 1:0.8.1-75.el6                   VirtualBox-4.3.x86_64 0:4.3.28_100309_el6-1                    
  acpid.x86_64 0:1.0.10-2.1.el6                                    aic94xx-firmware.noarch 0:30-2.el6                            akonadi.x86_64 0:1.2.1-3.el6                                 alsa-plugins-pulseaudio.x86_64 0:1.0.21-3.el6                  
  authconfig-gtk.x86_64 0:6.1.12-19.el6                            autofs.x86_64 1:5.0.5-109.0.1.el6_6.1                         b43-openfwwf.noarch 0:5.2-4.el6                              bfa-firmware.noarch 0:3.2.23.0-2.el6                           
  biosdevname.x86_64 0:0.5.1-1.el6                                 bluez.x86_64 0:4.66-1.el6                                     brasero-nautilus.x86_64 0:2.28.3-6.el6                       certmonger.x86_64 0:0.75.13-1.el6                              
  cifs-utils.x86_64 0:4.8.1-19.el6                                 compiz.x86_64 0:0.8.2-24.el6                                  compiz-gnome.x86_64 0:0.8.2-24.el6                           control-center.x86_64 1:2.28.1-39.el6                          
  control-center-extra.x86_64 1:2.28.1-39.el6                      cpuspeed.x86_64 1:1.5-20.0.1.el6_4                            crda.x86_64 0:1.1.3_2014.06.13-1.el6                         cronie.x86_64 0:1.4.4-12.el6                                   
  cronie-anacron.x86_64 0:1.4.4-12.el6                             crontabs.noarch 0:1.10-33.el6                                 cryptsetup-luks.x86_64 0:1.2.0-11.el6                        cryptsetup-luks-libs.x86_64 0:1.2.0-11.el6                     
  cups.x86_64 1:1.4.2-67.el6                                       cyrus-sasl.x86_64 0:2.1.23-15.el6_6.2                         desktop-effects.x86_64 0:0.8.4-7.el6                         device-mapper.x86_64 0:1.02.90-2.el6_6.1                       
  device-mapper-event.x86_64 0:1.02.90-2.el6_6.1                   device-mapper-event-libs.x86_64 0:1.02.90-2.el6_6.1           device-mapper-libs.x86_64 0:1.02.90-2.el6_6.1                dhclient.x86_64 12:4.1.1-43.P1.0.1.el6_6.1                     
  dmraid.x86_64 0:1.0.0.rc16-11.el6                                dmraid-events.x86_64 0:1.0.0.rc16-11.el6                      dnsmasq.x86_64 0:2.48-14.el6                                 docker-io.x86_64 0:1.5.0-1.el6                                 
  dracut.noarch 0:004-356.0.2.el6_6.2                              dracut-kernel.noarch 0:004-356.0.2.el6_6.2                    eog.x86_64 0:2.28.2-4.el6                                    evince.x86_64 0:2.28.2-14.el6_0.1                              
  file-roller.x86_64 0:2.28.2-7.el6                                foomatic.x86_64 0:4.0.4-3.el6                                 foomatic-db.noarch 0:4.0-7.20091126.el6                      foomatic-db-ppds.noarch 0:4.0-7.20091126.el6                   
  fuse.x86_64 0:2.8.3-4.0.2.el6                                    gcalctool.x86_64 0:5.28.2-3.el6                               gdm.x86_64 1:2.30.4-64.0.1.el6                               gdm-plugin-fingerprint.x86_64 1:2.30.4-64.0.1.el6              
  gdm-user-switch-applet.x86_64 1:2.30.4-64.0.1.el6                gedit.x86_64 1:2.28.4-3.el6                                   git.x86_64 0:1.7.1-3.el6_4.1                                 glx-utils.x86_64 0:10.1.2-2.el6                                
  gnome-applets.x86_64 1:2.28.0-7.el6                              gnome-bluetooth.x86_64 0:2.28.6-8.el6                         gnome-disk-utility.x86_64 0:2.30.1-2.el6                     gnome-disk-utility-libs.x86_64 0:2.30.1-2.el6                  
  gnome-disk-utility-ui-libs.x86_64 0:2.30.1-2.el6                 gnome-packagekit.x86_64 0:2.28.3-9.el6                        gnome-panel.x86_64 0:2.30.2-15.el6                           gnome-power-manager.x86_64 0:2.28.3-7.el6_4                   
  
----------------------------  
  
目的:提取每个包的名字,然后给yum安装。

一气呵成:
for i in $(cat 1.log |xargs -n 2 |awk ‘{print $1}‘);do yum -y install $i;done

傻瓜点儿的办法:
cat 1.log |awk -F‘ ‘ ‘{print $1}‘ >2.log
cat 1.log |awk -F‘ ‘ ‘{print $3}‘ >>2.log
cat 1.log |awk -F‘ ‘ ‘{print $5}‘ >>2.log
cat 1.log |awk -F‘ ‘ ‘{print $7}‘ >>2.log
cat 2.log |xargs -i yum -y install {}
时间: 2024-10-06 18:48:05

xargs用法示例的相关文章

Linux中 find 常见用法示例

Linux中find常见用法示例 #find path -option [ -print ] [ -exec -ok command ] {} \; #-print 将查找到的文件输出到标准输出 #-exec command {} \; —–将查到的文件执行command操作,{} 和 \;之间有空格.其实在命令执行的时候"{}"将被find到的结果替换掉,因此将"{}"看成find到的文件来进行操作就很容易理解这个选项了. #-ok 和-exec相同,只不过在操作

Linux find 用法示例(摘抄)

Linux中find常见用法示例 ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数: pathname: find命令所查找的目录路径.例如用.来表示当前目录,用/来表示系统根目录.-print: find命令将匹配的文件输出到标准输出.-exec: find命令对匹配的文件执行该参数所给出的shell命令.相应命令的形式为'command' { } \;,注意{ }和\:之间的

Linux中find命令大全-用法示例

Linux中find常见用法示例 find path -option [ -print ] [ -exec -ok command ] {} \; find命令的参数: path: find命令所查找的目录路径.例如用.来表示当前目录,用/来表示系统根目录.-print: find命令将匹配的文件输出到标准输出.-exec: find命令对匹配的文件执行该参数所给出的shell命令.相应命令的形式为'command' { } \;,注意{ }和\:之间的空格.-ok: 和-exec的作用相同,只

openat与open的区别及用法示例

从2.6.16版本开始,GNU/Linux引入opeant系统调用: #define _XOPEN_SOURCE 700 /* Or define _POSIX_C_SOURCE >= 200809 */ #include <fcntl.h> int openat(int dirfd , const char * pathname , int flags , ... /* mode_t mode */); Returns file descriptor on success, or –1

wxpython布局管理部件wx.gridbagsizer用法示例

text = ("This is text box")         panel = wx.Panel(self, -1)         chkAll1 = wx.CheckBox(panel, ID_CHKBOX_CAN_SEL_ALL, u'全选')                chkKnown = wx.CheckBox(panel, ID_CHKBOX_CAN_UNKNOWN, u'不会')         chkUnknow = wx.CheckBox(panel, I

C#中HashTable的用法示例2

命名空间 System.Collections 名称 哈希表(Hashtable) 描述 用于处理和表现类似keyvalue的键值对,其中key通常可用来快速查找,同时key是区分大小写:value用于存储对应于key的值.Hashtable中keyvalue键值对均为object类型,所以Hashtable可以支持任何类型的keyvalue键值对. 二,哈希表的简单操作 Hashtable hshTable = new Hashtable(); //  创建哈希表hshTable .Add("

C#中HashTable的用法示例1

一,哈希表(Hashtable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似keyvalue的键值对,其中key通常可用来快速查找,同时key是区分大小写:value用于存储对应于key的值.Hashtable中keyvalue键值对均为object类型,所以Hashtable可以支持任何类型的keyvalue键值对. 二,哈希表的简单操作 在哈希表中添加一个keyvalue键值对:HashtableO

oracle中to_date详细用法示例(oracle日期格式转换)

这篇文章主要介绍了oracle中to_date详细用法示例,包括期和字符转换函数用法.字符串和时间互转.求某天是星期几.两个日期间的天数.月份差等用法 TO_DATE格式(以时间:2007-11-02 13:45:25为例) 1. 日期和字符转换函数用法(to_date,to_char) select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as nowTime from dual; //日期转化为字符串 select to_char(sysdate,'

[email&#160;protected] $location.path(&#39;/login&#39;)-$location服务用法示例

$httpProvider interceptor .factory('auth403', ['$rootScope', '$q', '$location', function auth403($rootScope, $q, $location) { return { request: function (config) { console.log(config); var start = new Date(); return config; }, response: function (res