shell操作文件的几条命令:删除最后一列、删除第一行、diff等
删除文件第一行: sed '1d' filename
删除文件最后一列: awk '{print $NF}' 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等的更多相关文章
- Shell的常用十八条命令
Shell的18条常用命令整理 1. ls: 类似于dos下的dir命令 ls最常用的参数有三个: -a -l -F. ls –a Linux上的文件以.开头的文件被系统视为隐藏文件,仅用ls命令是看 ...
- 3.shell编程-文件查找之find命令
3.1.语法格式 find [路劲][选项][操作] 选项参数对照表 3.2.-name 查找/etc/目录下以.conf结尾的文件 find /etc/ -name "*.conf&quo ...
- shell遍历文件夹并执行命令
背景: 有一个源码包里面包含很多子目录和makefile,打包后的压缩包太大,需要将make生成的所有二进制文件删除然后再打包. 需求: 因此,要求在制定目录的所有递归子目录中执行make clean ...
- shell脚本--文件查找之find命令
首先是通过文件名称来查找,需要使用一个-name参数. 查询以 .txt结尾的文件,和以 t 开头的文件: ubuntu@ubuntu:~/test$ ls one.txt three.txt tw ...
- Hadoop2.7.6_04_HDFS的Shell操作与常见问题
1. HDFS的shell操作 1.1. 支持的命令及参数 [yun@mini05 zhangliang]$ hadoop fs Usage: hadoop fs [generic options] ...
- (三)linux 学习 --操作文件和目录
The Linux Command Line 读书笔记 - 部分内容来自 http://billie66.github.io/TLCL/book/chap05.html 文章目录 通配符 字符范围 ` ...
- 五、Zookeeper的Shell操作
前文 一.CentOS7 hadoop3.3.1安装(单机分布式.伪分布式.分布式 二.JAVA API实现HDFS 三.MapReduce编程实例 四.Zookeeper3.7安装 Zookeepe ...
- supervisor的command执行两条命令
如下supervisor的进程的comand配置参数只能写一个命令 1.要执行多条命令,可以写个sh文件包含多条命令,然后sh -x xxxx.sh,但这样又多了一个文件, 2.把所有命令放在字符 ...
- 用日志记录Linux用户执行的每一条命令(history)
工作中,需要把用户执行的每一个命令都记录下来,并发送到日志服务器的需求,为此我做了一个简单的解决方案.这个方案会在每个用户退出登录 时把用户所执行的每一个命令都发送给日志守护进程rsyslogd,你也 ...
随机推荐
- Arch Linux 安装记录
Arch Linux 安装记录 基本上参考wiki上的新手指南,使用arch 2014.6.1 iso安装 设置网络 有线网络 Arch Linux 默认开启DHCP. 静态ip 首先关闭DHCP:s ...
- 【MySQL】MHA部署与MasterFailover代码分析
官网:https://code.google.com/p/mysql-master-ha/ 参考:http://blog.csdn.net/wulantian/article/details/1328 ...
- 将Eclipse项目导入Android Studio出现中文乱码的问题
以前一直以Eclipse开发项目,最近正在研究Android Studio的使用,首先想到到的是将Eclispe项目导入AS. 可以方便查看以前写过的代码,然后出现了中文乱码的问题,通过搜索了一些资料 ...
- php实现文件上传的源码
php实现文件上传的源码,更多php技术开发就去php教程网,http://php.662p.com <?php ##author :Androidyue ##sina @androidyue ...
- slf4j+log4j配置
下载三个包: 三个包分别是:log4j的API包,slf4j的API包,slf4j对log4j的适配包. 选择使用slf4j一个重要的原因是支持占位符{},不用频繁操作字符串对象. 实现代码如下: i ...
- 针对BootStrap中tabs控件的美化和完善
BootStrap中的tabs控件以其简单易用而很受广大开发者的欢迎.但是,它的样式比较单一,如何才能在其原有的基础上做出更加美观的效果呢,我一直在考虑这个问题.另外,Bootstrap中的tabs必 ...
- windwos异地备份Mysql数据库
@echo off@title Mysqlbackup echo MySQL数据库备份 echo ***********************echo Today %date%echo Time % ...
- PL/SQL Developer基本用法
一.新建存储过程
- c# 实现串口编程-操作LED屏幕
串口编程主要用到SerialPort这个类,主要实现对串口发送字节数组然后点阵屏显示相关信息,其实这个功能很简单下面给大家把整体思路用流程图展现如下:. 其实整体思路就如流程图.下面是整个流程图的一个 ...
- ThinkPHP之中的getField、Find、select、返回数据类型详解(ThinkPHP之中所有数据读取了)
小李子:用于演示作用的数据库表:customers 官方解读: “ 读取数据集其实就是获取数据表中的多行记录(以及关联数据),使用select方法 ” $customers=D('customers' ...