Skip to main content
edited body
Source Link

I have a list with the names of several files:

file1
file2

I would like to add at the end of the 1st line of each file the name of the file e.g.:

file 1 first row will be

> ATCGCCfile1

file 2 first row will be

> ATTTCCfile1ATTTCCfile2

My idea is now to create a variable a with the file names' name:

a="file1 file2"

loop over the files and add the word re-calling the index:

for i in $a; do cat $i | awk '{print $0"$i"}' > $i.extended_word.txt; done

however in the output the awk '{print $0"$i"}' does not work and gives me just the $i without the name of the file e.g. in case of the 1st file >ATCGCC$i .

What am i doing wrong? I also tried the parentesis ( awk '{print $0"${i}"}') but without succeed.

I have a list with the names of several files:

file1
file2

I would like to add at the end of the 1st line of each file the name of the file e.g.:

file 1 first row will be

> ATCGCCfile1

file 2 first row will be

> ATTTCCfile1

My idea is now to create a variable a with the file names' name:

a="file1 file2"

loop over the files and add the word re-calling the index:

for i in $a; do cat $i | awk '{print $0"$i"}' > $i.extended_word.txt; done

however in the output the awk '{print $0"$i"}' does not work and gives me just the $i without the name of the file e.g. in case of the 1st file >ATCGCC$i .

What am i doing wrong? I also tried the parentesis ( awk '{print $0"${i}"}') but without succeed.

I have a list with the names of several files:

file1
file2

I would like to add at the end of the 1st line of each file the name of the file e.g.:

file 1 first row will be

> ATCGCCfile1

file 2 first row will be

> ATTTCCfile2

My idea is now to create a variable a with the file names' name:

a="file1 file2"

loop over the files and add the word re-calling the index:

for i in $a; do cat $i | awk '{print $0"$i"}' > $i.extended_word.txt; done

however in the output the awk '{print $0"$i"}' does not work and gives me just the $i without the name of the file e.g. in case of the 1st file >ATCGCC$i .

What am i doing wrong? I also tried the parentesis ( awk '{print $0"${i}"}') but without succeed.

deleted 3 characters in body
Source Link

I have a list with the names of of several filefiles:

file1
file2

I would like to add at the end of the 1st line of each file the name of the file e.g.:

file 1 first row will be

> ATCGCCfile1

file 2 first row will be

> ATTTCCfile1

My idea is now to create a variable a with the file names' name:

a="file1 file2"

loop over the files and add the word re-calling the index:

for i in $a; do cat $i | awk '{print $0"$i"}' > $i.extended_word.txt; done

however in the output the awk '{print $0"$i"}' does not work and gives me just the $i without the name of the file e.g. in case of the 1st file >ATCGCC$i .

What am i doing wrong? I also tried the parentesis ( awk '{print $0"${i}"}') but without succeed.

I have a list with the names of of several file:

file1
file2

I would like to add at the end of the 1st line of each file the name of the file e.g.:

file 1 first row will be

> ATCGCCfile1

file 2 first row will be

> ATTTCCfile1

My idea is now to create a variable a with the file names' name:

a="file1 file2"

loop over the files and add the word re-calling the index:

for i in $a; do cat $i | awk '{print $0"$i"}' > $i.extended_word.txt; done

however in the output the awk '{print $0"$i"}' does not work and gives me just the $i without the name of the file e.g. in case of the 1st file >ATCGCC$i .

What am i doing wrong? I also tried the parentesis ( awk '{print $0"${i}"}') but without succeed.

I have a list with the names of several files:

file1
file2

I would like to add at the end of the 1st line of each file the name of the file e.g.:

file 1 first row will be

> ATCGCCfile1

file 2 first row will be

> ATTTCCfile1

My idea is now to create a variable a with the file names' name:

a="file1 file2"

loop over the files and add the word re-calling the index:

for i in $a; do cat $i | awk '{print $0"$i"}' > $i.extended_word.txt; done

however in the output the awk '{print $0"$i"}' does not work and gives me just the $i without the name of the file e.g. in case of the 1st file >ATCGCC$i .

What am i doing wrong? I also tried the parentesis ( awk '{print $0"${i}"}') but without succeed.

Source Link

Add list of words at the end of the 1st line in a loop

I have a list with the names of of several file:

file1
file2

I would like to add at the end of the 1st line of each file the name of the file e.g.:

file 1 first row will be

> ATCGCCfile1

file 2 first row will be

> ATTTCCfile1

My idea is now to create a variable a with the file names' name:

a="file1 file2"

loop over the files and add the word re-calling the index:

for i in $a; do cat $i | awk '{print $0"$i"}' > $i.extended_word.txt; done

however in the output the awk '{print $0"$i"}' does not work and gives me just the $i without the name of the file e.g. in case of the 1st file >ATCGCC$i .

What am i doing wrong? I also tried the parentesis ( awk '{print $0"${i}"}') but without succeed.