Unix脚本删除CSV文件的第一行 [英] Unix script to remove the first line of a CSV file

查看:275
本文介绍了Unix脚本删除CSV文件的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前说过,我不是很擅长脚本,所以下面的我从共享目录复制文件,我的地方,我改变他们的权限。但是我想删除每个CSV文件中的第一行 - 标题,然后我想让它每小时运行一次。

  cd / users 
scp dehpc14_Disk_Quota_Report.csv / h / u544835
scp dehpc14_User_Disk_Usage.csv / h / u544835
cd / h / u544835
chmod 755 dehpc14_Disk_Quota_Report.csv
chmod 755 dehpc14_User_Disk_Usage.csv



* insert delete csv first line here * / strong>



任何人都可以帮助我删除CSV文件的第一行,并让它每小时自动运行,或者指示我

解决方案

您可以使用 sed

删除文件的第一行, / code>:

  sed -i''1d file.csv 

如果您只想获取没有第一行的文件内容,并修改文件,请删除 -i''标志:

  sed 1d file.csv 

这里1d是要执行的命令:




  • 1 =>行在哪里行动

  • d => b


所以 1d 表示删除第1行



得到第一行,可以使用sed:

  sed -n 1p file.csv 



这里 p 代表'print'或

  sed 1q file.csv 


I've stated before I'm not very good at scripting so what I have below copies files from a share directory to mine where I change their permissions. But then I wanted to remove the first line in each of the CSV files — the headings — and then I wanted to get this to run every hour.

cd /users
scp dehpc14_Disk_Quota_Report.csv /h/u544835
scp dehpc14_User_Disk_Usage.csv /h/u544835
cd /h/u544835
chmod 755 dehpc14_Disk_Quota_Report.csv
chmod 755 dehpc14_User_Disk_Usage.csv

* insert delete csv first line here *

Can anyone help me with deleting the first line of the CSV file and getting this to run automatically every hour, for example, or direct me to something I might understand to get cracking with it?

解决方案

You can delete the first line of a file using sed:

sed -i '' 1d file.csv

If you just want to get the contents of the file without the first line, and without modifying the file, remove the -i '' flag:

sed 1d file.csv

Here 1d is the command to execute:

  • 1 => line where to act
  • d => delete

So 1d means 'delete line 1'

If you want to get the first line, you can use sed too:

sed -n 1p file.csv

Here p stands for 'print' or

sed 1q file.csv

(see William Pursell's comment)

这篇关于Unix脚本删除CSV文件的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆