zoukankan      html  css  js  c++  java
  • shell专题(十一):企业真实面试题(重点)

    11.1 京东

    问题1:使用Linux命令查询file1中空行所在的行号

    答案:
    [atguigu@hadoop102 datas]$ awk '/^$/{print NR}' sed.txt 
    5

    问题2:有文件chengji.txt内容如下:

    张三 40

    李四 50

    王五 60

    使用Linux命令计算第二列的和并输出

     

    [atguigu@hadoop102 datas]$ cat chengji.txt | awk -F " " '{sum+=$2} END{print sum}'
    150

     

    11.2 搜狐&和讯网

    问题1:Shell脚本里如何检查一个文件是否存在?如果不存在该如何处理?

    #!/bin/bash
    
    if [ -f file.txt ]; then
       echo "文件存在!"
    else
       echo "文件不存在!"
    fi

    11.3 新浪

    问题1:用shell写一个脚本,对文本中无序的一列数字排序

    [root@CentOS6-2 ~]# cat test.txt
    9
    8
    7
    6
    5
    4
    3
    2
    10
    1
    [root@CentOS6-2 ~]# sort -n test.txt|awk '{a+=$0;print $0}END{print "SUM="a}'
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    SUM=55

    11.3 金和网络

    问题1:请用shell脚本写出查找当前文件夹(/home)下所有的文本文件内容中包含有字符”shen”的文件名称

    [atguigu@hadoop102 datas]$ grep -r "shen" /home | cut -d ":" -f 1
    /home/atguigu/datas/sed.txt
    /home/atguigu/datas/cut.txt

     

    问题1:使用Linux命令查询file1中空行所在的行号

    答案

    [atguigu@hadoop102 datas]$ awk '/^$/{print NR}' sed.txt

    5

    问题2:有文件chengji.txt内容如下:

    张三 40

    李四 50

    王五 60

    使用Linux命令计算第二列的和并输出

    [atguigu@hadoop102 datas]$ cat chengji.txt | awk -F " " '{sum+=$2} END{print sum}'

    150

  • 相关阅读:
    支持向量机SVM知识点概括
    决策树知识点概括
    HDU 3081 Marriage Match II
    HDU 3572 Task Schedule
    HDU 4888 Redraw Beautiful Drawings
    Poj 2728 Desert King
    HDU 3926 Hand in Hand
    HDU 1598 find the most comfortable road
    HDU 4393 Throw nails
    POJ 1486 Sorting Slides
  • 原文地址:https://www.cnblogs.com/qiu-hua/p/13220097.html
Copyright © 2011-2022 走看看