簡體   English   中英

連接 sed 命令

[英]Concatenating sed commands

我有一個 .txt 文件,我使用三個 sed 命令來操作它。 首先,我通過用制表符替換逗號 (A) 將其轉換為 .csv,然后刪除第 1-8 行 (B),然后刪除第 9 行 (C) 開頭的“#”。

(A) sed 's/\t/,/g' individuals/$message/$message.txt > individuals/$message/$message.csv
(B) sed -i 1,8d individuals/$message/$message.csv
(C) sed -i 's/.\{2\}//' individuals/$message/$message.csv

有沒有更好的方法,也許將這三個命令集成到一個命令中? 它不需要使用 sed 來完成,但需要通過 bash 命令來完成。

這是我的數據示例:

# This data file generated by PLINK at: Mon Jul 11 16:18:56 2022
#
# Below is a text version of your data.  Fields are TAB-separated.
# Each line corresponds to a single SNP.  For each SNP, we provide its
# identifier, its location on a reference human genome, and the genotype call.
# For further information (e.g. which reference build was used), consult the
# original source of your data.
#
# rsid  chromosome  position    genotype
22:16050607G-A  22  16050607    GG

我非常感謝您的幫助!

PS:第 9 行是# rsid chromossome...之一,它應該保存在文件中,只是沒有#

使用多個-e選項在一次調用中執行多個sed命令。

sed -e '1,8d' -e '9s/^# //' -e '9,$s/\t/,/g' "individuals/$message/$message.txt" > "individuals/$message/$message.csv"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM