Home > Net >  Tab separated file with file names in first column and path in the second column
Tab separated file with file names in first column and path in the second column

Time:07-14

I'm new to linux and I need to find a way to have a tab delimited file that read files in a directory and put a first column with names and a second column with the path like:

xxx ---> /PATH/xxx.fasta

I have found the script bellow that partially do the job but it can also add the path to the first column which I don't want to. Can somebody help me please. Thank you in advance

paste -d '\t' \
    <(printf "%s\n" PATH/*.fasta | sort) \
    | sed 's/\(.*\).fasta/\1\t\1.fasta/' \
    > out.txt

CodePudding user response:

Try this:

for f in PATH/*.fasta; do
    printf '%s\t%s\n' "$(basename "$f" .fasta)" "$f"
done > out.txt

CodePudding user response:

find and sed can do this for you:

find /PATH/*.fasta | sed -E 's#((/[^/] )*/([^/] )\.[^.] )$#\3\t\1#' > out.txt
  • Related