Score:0

How to add a filename to multiple text files which are tab separated at 7 column

to flag

I want to add the filename at 7 column for multiple tab separated text file My file looks right now like this:

chr1    467293640   .   G   A   35.3963 PASS    AF

I want output like this

chr1    467293640   .   G   A   35.3963 s372-937    AF

Right now i am using a code like this

awk -vOFS='\t' '{$7 = "s372-937"; print}' 

for a single file but how can i perform for multiple files

ar flag
Which distro and version of Linux are you using? Which shell are you using? Does each file have only one line? Is `s372-937` the name of the file you are writing to, or is it the name of some other file? Please [edit your question](https://askubuntu.com/posts/1438911/edit) and add these information.
hr flag
You can access the current filename in awk using the `FILENAME` built-in variable - see for example [The GNU Awk User's Guide: 7.5.2 Built-in Variables That Convey Information](https://www.gnu.org/software/gawk/manual/gawk.html#Auto_002dset)
terdon avatar
cn flag
Is that _really_ your file or is this a VCF file that also contains headers starting with `#` that need to be excluded? Also, what is the file name? Can we just use the actual name of each file as steeldriver explains above? Finally, if this _is_ a VCF file, adding the file name will break it and programs that expect VCF won't be able to handle it.
Alekhya Vemula avatar
to flag
Thanks @steeldriver it worked by using the FILENAME built-in variable.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.