shell脚本学习每日一句(2)

5月21号 晚上8点更新

employee文件中记录了工号和姓名

employee.txt:
100 Jason Smith 
200 John Doe 
300 Sanjay Gupta 
400 Ashok Sharma 
bonus文件中记录工号和工资
bonus.txt:
100 $5,000 
200 $500 
300 $3,000 
400 $1,250 
要求把两个文件合并并输出如下
处理结果:
400 ashok sharma $1,250
100 jason smith  $5,000
200 john doe  $500

300 sanjay gupta  $3,000

[root@fsailing1 shell]# vim employee.txt [root@fsailing1 shell]# vim bonus.txt [root@fsailing1 shell]# paste employee.txt bonus.txt 100 Jason Smith 100 $5,000 200 John Doe 200 $500 300 Sanjay Gupta 300 $3,000 400 Ashok Sharma 400 $1,250 [root@fsailing1 shell]# paste employee.txt bonus.txt |awk '{print $1 $2 $3 $ 5}' 100JasonSmith$5,000 200JohnDoe$500 300SanjayGupta$3,000 400AshokSharma$1,250[root@fsailing1 shell]# paste employee.txt bonus.txt |awk '{print $1,$2,$3,$5}' 100 Jason Smith $5,000 200 John Doe $500 300 Sanjay Gupta $3,000 400 Ashok Sharma $1,250[root@fsailing1 shell]# paste employee.txt bonus.txt |awk '{print $1 , $2 , $3 , $5}'|tr '[:lower:]' '[:upper:]' 100 JASON SMITH $5,000 200 JOHN DOE $500 300 SANJAY GUPTA $3,000 400 ASHOK SHARMA $1,250 [root@fsailing1 shell]# paste employee.txt bonus.txt |awk '{print $1 , $2 , $3 , $5}'|tr '[:upper:]' '[:lower:]'|sort -k 2 400 ashok sharma $1,250 100 jason smith $5,000 200 john doe $500 300 sanjay gupta $3,000

5月22号 下午2点

文件格式如下:

100
a         100
b         -50
c         -20
d         -30
要求输出结果为:
100
a          100
200
b          -50
150
c           -20
130
d          -30

100

[root@fsailing1 shell]# awk '{print $0;print $1}' test.txt 100 100 a 100 a b -50 b c -20 c d -30 d [root@fsailing1 shell]# awk 'NR==1{sum=$1;print $0}' test.txt NR表示awk读到的文件行数。 100 [root@fsailing1 shell]# awk 'NR==1{sum=$1;print $0} NR!=1{print $0;print sum+=$2}' test.txt 100 a 100 200 b -50 150 c -20 130 d -30 100

5月23号 20点

服务器基本信息:

[root@fsailing1 ~]# cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 37 model name : Intel(R) Pentium(R) CPU G6950 @ 2.80GHz stepping : 2 cpu MHz : 1197.000 cache size : 3072 KB [root@fsailing1 ~]# uname -a Linux fsailing1 2.6.18-274.18.1.el5PAE #1 SMP Thu Feb 9 13:25:50 EST 2012 i686 i686 i386 GNU/Linux [root@fsailing1 ~]# cat /proc/meminfo MemTotal: 4064112 kB MemFree: 688688 kB Buffers: 397144 kB Cached: 2486648 kB SwapCached: 0 kB Active: 1543784 kB[root@fsailing1 ~]# fdisk -l Disk /dev/sda: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 25 200781 83 Linux /dev/sda2 26 1069 8385930 82 Linux swap / Solaris /dev/sda3 1070 1706 5116702+ 83 Linux /dev/sda4 1707 60801 474680587+ f W95 Ext'd (LBA) /dev/sda5 1707 2343 5116671 83 Linux /dev/sda6 2344 2980 5116671 83 Linux /dev/sda7 2981 60801 464447151 83 Linux

5月25号 下午4点

查看系统的运行级别:

0 – 系统停机状态
1 – 单用户工作状态
2 – 多用户状态(没有NFS)
3 – 多用户状态(有NFS)
Redhat的默认运行级
4 – 系统未使用,留给用户,一般在系统出现故障时使用
5 – X11控制台(xdm,gdm或kdm)
6 – 系统正常关闭并重新启动
Linux最常用的运行级别是3 (linux系统启动后进入字符模式就是此运行级别)
和5(linux系统启动后进入图形模式是允许级别5)

[root@fsailing1 ~]# less /etc/inittab # Default runlevel. The runlevels used by RHS are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:5:initdefault: # System initialization. si::sysinit:/etc/rc.d/rc.sysinit l0:0:wait:/etc/rc.d/rc 0 l1:1:wait:/etc/rc.d/rc 1 l2:2:wait:/etc/rc.d/rc 2 l3:3:wait:/etc/rc.d/rc 3 l4:4:wait:/etc/rc.d/rc 4 l5:5:wait:/etc/rc.d/rc 5 l6:6:wait:/etc/rc.d/rc 6







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值