删除文件第一行: sed '1d' filename

删除文件最后一列: awk '{print $NF}' filename

awk删除重复行的命令:awk '{if (!seen[$0]++) {print $0;}}' filename

比较文件的两种方法:

1)comm -3 --nocheck-order file1 file2

2) grep -v -f file1 file2 :输出file2中有file1中没有的行

当然还有diff file1 file2

贴一段昨天写的shell脚本~

#!/bin/bash
date_time=`date +'%H_%M_%S'`
yesterday=`date -d"-1 day" +'%Y_%m_%d'`
today=`date +'%Y_%m_%d'`
date_day_time=`date +'%Y_%m_%d_%H_%M_%S'` mkdir /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/same_similiar_log/$today # begin to get input files which haven't been deal with
today_input=/home/crawler/petabyte/crawllog/news_data/$today
yesterday_input=/home/crawler/petabyte/crawllog/news_data/$yesterday /opt/hadoop/program/bin/hadoop fs -ls $yesterday_input/ > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_get
/opt/hadoop/program/bin/hadoop fs -ls $today_input/ >> /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_get sed '1d' /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_get > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_get_without_first_line awk '{print $NF}' /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_get_without_first_line > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_input #comm - --nocheck-order /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_input /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/input_done > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/today_diff grep -v -f /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/input_done /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_input > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/today_diff awk '{print $NF}' /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/today_diff > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/today_new_input mv /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_input /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/input_done # begin to compute same_similary_news
inputfile1=""
while read line
do
inputfile1=$inputfile1,${line}
done < /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/input_done
echo $inputfile1

shell操作文件的几条命令:删除最后一列、删除第一行、diff等的更多相关文章

  1. Shell的常用十八条命令

    Shell的18条常用命令整理 1. ls: 类似于dos下的dir命令 ls最常用的参数有三个: -a -l -F. ls –a Linux上的文件以.开头的文件被系统视为隐藏文件,仅用ls命令是看 ...

  2. 3.shell编程-文件查找之find命令

    3.1.语法格式 find [路劲][选项][操作] 选项参数对照表 3.2.-name 查找/etc/目录下以.conf结尾的文件 find /etc/ -name "*.conf&quo ...

  3. shell遍历文件夹并执行命令

    背景: 有一个源码包里面包含很多子目录和makefile,打包后的压缩包太大,需要将make生成的所有二进制文件删除然后再打包. 需求: 因此,要求在制定目录的所有递归子目录中执行make clean ...

  4. shell脚本--文件查找之find命令

    首先是通过文件名称来查找,需要使用一个-name参数. 查询以  .txt结尾的文件,和以 t 开头的文件: ubuntu@ubuntu:~/test$ ls one.txt three.txt tw ...

  5. Hadoop2.7.6_04_HDFS的Shell操作与常见问题

    1. HDFS的shell操作 1.1. 支持的命令及参数 [yun@mini05 zhangliang]$ hadoop fs Usage: hadoop fs [generic options] ...

  6. (三)linux 学习 --操作文件和目录

    The Linux Command Line 读书笔记 - 部分内容来自 http://billie66.github.io/TLCL/book/chap05.html 文章目录 通配符 字符范围 ` ...

  7. 五、Zookeeper的Shell操作

    前文 一.CentOS7 hadoop3.3.1安装(单机分布式.伪分布式.分布式 二.JAVA API实现HDFS 三.MapReduce编程实例 四.Zookeeper3.7安装 Zookeepe ...

  8. supervisor的command执行两条命令

    如下supervisor的进程的comand配置参数只能写一个命令 1.要执行多条命令,可以写个sh文件包含多条命令,然后sh -x   xxxx.sh,但这样又多了一个文件, 2.把所有命令放在字符 ...

  9. 用日志记录Linux用户执行的每一条命令(history)

    工作中,需要把用户执行的每一个命令都记录下来,并发送到日志服务器的需求,为此我做了一个简单的解决方案.这个方案会在每个用户退出登录 时把用户所执行的每一个命令都发送给日志守护进程rsyslogd,你也 ...

随机推荐

  1. 分区的4k对齐

    4k对齐的原理 4k对齐的磁盘性能比非对齐的大致提升在5%-10%左右. fdisk -H 224 -S 56 /dev/sdx #创建分区 fdisk -lu /dev/sdx #验证对齐

  2. 【MySQL】SQL语句嵌套1

    mysql中You can't specify target table <tbl> for update in FROM clause错误的意思是说,不能先select出同一表中的某些值 ...

  3. DEDE的data目录名称修改方法

    DEDE的data目录名称修改方法 为了最大限度的减少网站被攻击的可能,需要将data目录改名,具体操作如下: 1.修改include目录下的common.inc.php这个文件.打开文件,找到第16 ...

  4. 学习使用LaTex排版文字输出为pdf(1)

    学习用latex写我的简历. 我在ubuntu环境下,先下载所需软件,命令百度就可以. 先创建一个a.tex,写上 \documentclass{article} \usepackage{CJK} \ ...

  5. Android IOS WebRTC 音视频开发总结(四十)-- 国内webrtc现状

    本文主要介绍目前国内webrtc开发现状,文章来自博客园rtc.blacker,支持原创,转载必须说明出处. 上次一国外合作伙伴问我国内rtc应用和开发状况怎样,哪些城市比较火,那些行业应用比较多,我 ...

  6. THINKPHP 清除HTML注释、换行符、空格、制表符等

    thinkphp3.2 3.2中取消了配置文件中的 'TMPL_STRIP_SPACE' 属性,所以我们先来修改:\ThinkPHP\Library\Think\Template.class.php ...

  7. partial class 说明

    C# 2.0 可以将类.结构或接口的定义拆分到两个或多个源文件中,在类声明前添加partial关键字即可. 例如:下面的PartialTest类 class PartialTest { string ...

  8. MongoDB用户管理

    1. 创建一个超级用户 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 use admin db.createUser(   {     user: "adminUse ...

  9. 3种方式实现Java多线程

    java中实现多线程的方法有两种:继承Thread类和实现runnable接口. 1.继承Thread类,重写父类run()方法 public class thread1 extends Thread ...

  10. Spring中Quartz调度器的使用

    一.Quartz的特点 * 按作业类的继承方式来分,主要有以下两种: 1.作业类继承org.springframework.scheduling.quartz.QuartzJobBean类的方式 2. ...