Print multiple filenames to specific lines in txt file Unicorn Meta Zoo #1: Why another...

Why did Israel vote against lifting the American embargo on Cuba?

Is this homebrew racial feat, Stonehide, balanced?

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

Has a Nobel Peace laureate ever been accused of war crimes?

Need of separate security plugins for both root and subfolder sites Wordpress?

What is the ongoing value of the Kanban board to the developers as opposed to management

How to get even lighting when using flash for group photos near wall?

What if Force was not Mass times Acceleration?

Error: Syntax error. Missing ')' for CASE Statement

What is /etc/mtab in Linux?

PIC mathematical operations weird problem

How long after the last departure shall the airport stay open for an emergency return?

Israeli soda type drink

Putting Ant-Man on house arrest

Does Mathematica have an implementation of the Poisson Binomial Distribution?

Is it acceptable to use working hours to read general interest books?

Protagonist's race is hidden - should I reveal it?

All ASCII characters with a given bit count

Suing a Police Officer Instead of the Police Department

Book with legacy programming code on a space ship that the main character hacks to escape

Why did C use the -> operator instead of reusing the . operator?

What is the best way to deal with NPC-NPC combat?

My admission is revoked after accepting the admission offer

Economise space with floats



Print multiple filenames to specific lines in txt file



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionextract text to csv file from output of reading multiple files into specific rowsHow to print file content only if the first line matches a certain pattern?script to parse file for two consecutive lines of unequal lengthPrint text before and after match, from a specific beginning and to an ending stringprint string between multiple brackets and multiple lines on a single lineremove a read from a fastq filePrint data between two lines (only if “range end” exists) from a text fileHow to prepend multiple lines to a fileRemove and Add sequence information at specific position in a fileFor loop to refer a file, search for matches on the first column and print the matching rows





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I am trying to print a list of filenames to a text file, with the requirement of printing certain filenames on the same line. For example, I have 4 files.



Paleo_R1.fastq
Paleo_R2.fastq
Vegan_R1.fastq
Vegan_R2.fastq


I want the output to be



Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


I know I can use the ls function and direct output to a text file, using ls >> file.txt but there are no options to print specific input line items to specific output lines.



Additionally, I am aware of that I can use for loops like this >



for file in Vegan*R1*.fastq; 
do echo $file ${file%_R1.fastq}_R2.fastq >> file.txt;
done


But I do not want to have a separate command for each filename, ie. for vegan and paleo.



Is there a way to print certain lines to specific output lines (print input lines 1 and 2 to output line 1, and input lines 3 and 4 to output line 2, and so on...)










share|improve this question







New contributor




Jamie Alfieri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Is the rule based on the file names (all files with the same first 5 characters), or every N=2 files regardless of name?

    – Jeff Schaller
    3 hours ago











  • The rule is based on every N=2 files regardless of name.

    – Jamie Alfieri
    3 hours ago


















0















I am trying to print a list of filenames to a text file, with the requirement of printing certain filenames on the same line. For example, I have 4 files.



Paleo_R1.fastq
Paleo_R2.fastq
Vegan_R1.fastq
Vegan_R2.fastq


I want the output to be



Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


I know I can use the ls function and direct output to a text file, using ls >> file.txt but there are no options to print specific input line items to specific output lines.



Additionally, I am aware of that I can use for loops like this >



for file in Vegan*R1*.fastq; 
do echo $file ${file%_R1.fastq}_R2.fastq >> file.txt;
done


But I do not want to have a separate command for each filename, ie. for vegan and paleo.



Is there a way to print certain lines to specific output lines (print input lines 1 and 2 to output line 1, and input lines 3 and 4 to output line 2, and so on...)










share|improve this question







New contributor




Jamie Alfieri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Is the rule based on the file names (all files with the same first 5 characters), or every N=2 files regardless of name?

    – Jeff Schaller
    3 hours ago











  • The rule is based on every N=2 files regardless of name.

    – Jamie Alfieri
    3 hours ago














0












0








0


1






I am trying to print a list of filenames to a text file, with the requirement of printing certain filenames on the same line. For example, I have 4 files.



Paleo_R1.fastq
Paleo_R2.fastq
Vegan_R1.fastq
Vegan_R2.fastq


I want the output to be



Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


I know I can use the ls function and direct output to a text file, using ls >> file.txt but there are no options to print specific input line items to specific output lines.



Additionally, I am aware of that I can use for loops like this >



for file in Vegan*R1*.fastq; 
do echo $file ${file%_R1.fastq}_R2.fastq >> file.txt;
done


But I do not want to have a separate command for each filename, ie. for vegan and paleo.



Is there a way to print certain lines to specific output lines (print input lines 1 and 2 to output line 1, and input lines 3 and 4 to output line 2, and so on...)










share|improve this question







New contributor




Jamie Alfieri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I am trying to print a list of filenames to a text file, with the requirement of printing certain filenames on the same line. For example, I have 4 files.



Paleo_R1.fastq
Paleo_R2.fastq
Vegan_R1.fastq
Vegan_R2.fastq


I want the output to be



Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


I know I can use the ls function and direct output to a text file, using ls >> file.txt but there are no options to print specific input line items to specific output lines.



Additionally, I am aware of that I can use for loops like this >



for file in Vegan*R1*.fastq; 
do echo $file ${file%_R1.fastq}_R2.fastq >> file.txt;
done


But I do not want to have a separate command for each filename, ie. for vegan and paleo.



Is there a way to print certain lines to specific output lines (print input lines 1 and 2 to output line 1, and input lines 3 and 4 to output line 2, and so on...)







linux files ls bioinformatics






share|improve this question







New contributor




Jamie Alfieri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Jamie Alfieri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Jamie Alfieri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 3 hours ago









Jamie AlfieriJamie Alfieri

1




1




New contributor




Jamie Alfieri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Jamie Alfieri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Jamie Alfieri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Is the rule based on the file names (all files with the same first 5 characters), or every N=2 files regardless of name?

    – Jeff Schaller
    3 hours ago











  • The rule is based on every N=2 files regardless of name.

    – Jamie Alfieri
    3 hours ago



















  • Is the rule based on the file names (all files with the same first 5 characters), or every N=2 files regardless of name?

    – Jeff Schaller
    3 hours ago











  • The rule is based on every N=2 files regardless of name.

    – Jamie Alfieri
    3 hours ago

















Is the rule based on the file names (all files with the same first 5 characters), or every N=2 files regardless of name?

– Jeff Schaller
3 hours ago





Is the rule based on the file names (all files with the same first 5 characters), or every N=2 files regardless of name?

– Jeff Schaller
3 hours ago













The rule is based on every N=2 files regardless of name.

– Jamie Alfieri
3 hours ago





The rule is based on every N=2 files regardless of name.

– Jamie Alfieri
3 hours ago










2 Answers
2






active

oldest

votes


















2














Maybe



$ ls *.fastq | xargs -n2
Bar_R1.fastq Bar_R2.fastq
Bar_R3.fastq Foo_R1.fastq
Foo_R2.fastq Foo_R3.fastq
Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


or for column output



$ ls *.fastq | xargs -n2 | column -t
Bar_R1.fastq Bar_R2.fastq
Bar_R3.fastq Foo_R1.fastq
Foo_R2.fastq Foo_R3.fastq
Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


(add >> file.txt to the command to append the output to the file)



Note that both examples only work with filenames without spaces.



For files with spaces:



$ for i in *.fastq; do echo -ne "$i"; done | xargs -0 -n2





share|improve this answer


























  • Note that redirecting this to a new file would include the name of that file in the output.

    – Kusalananda
    3 hours ago











  • Thanks @Kusalananda, fixed by workaround. I guess it's time for bed.

    – Freddy
    2 hours ago



















0














Using the solution you already have, it's just a matter of not specifying the filename prefix Vegan:



for file in *_R1.fastq; do
printf '%s %sn' "$file" "${file%_R1.fastq}_R2.fastq"
done >file.txt


Using printf and redirecting after the loop instead of for each output command is just my personal preference.



For the given filenames, this generates file.txt with



Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq





share|improve this answer
























  • Yes this would work with the data I supplied. However, this would not work if the files were not named in a consistent manner.

    – Jamie Alfieri
    2 hours ago











  • @JamieAlfieri Do give an example of that, because there is none in the question.

    – Kusalananda
    2 hours ago














Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Jamie Alfieri is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f515330%2fprint-multiple-filenames-to-specific-lines-in-txt-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Maybe



$ ls *.fastq | xargs -n2
Bar_R1.fastq Bar_R2.fastq
Bar_R3.fastq Foo_R1.fastq
Foo_R2.fastq Foo_R3.fastq
Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


or for column output



$ ls *.fastq | xargs -n2 | column -t
Bar_R1.fastq Bar_R2.fastq
Bar_R3.fastq Foo_R1.fastq
Foo_R2.fastq Foo_R3.fastq
Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


(add >> file.txt to the command to append the output to the file)



Note that both examples only work with filenames without spaces.



For files with spaces:



$ for i in *.fastq; do echo -ne "$i"; done | xargs -0 -n2





share|improve this answer


























  • Note that redirecting this to a new file would include the name of that file in the output.

    – Kusalananda
    3 hours ago











  • Thanks @Kusalananda, fixed by workaround. I guess it's time for bed.

    – Freddy
    2 hours ago
















2














Maybe



$ ls *.fastq | xargs -n2
Bar_R1.fastq Bar_R2.fastq
Bar_R3.fastq Foo_R1.fastq
Foo_R2.fastq Foo_R3.fastq
Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


or for column output



$ ls *.fastq | xargs -n2 | column -t
Bar_R1.fastq Bar_R2.fastq
Bar_R3.fastq Foo_R1.fastq
Foo_R2.fastq Foo_R3.fastq
Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


(add >> file.txt to the command to append the output to the file)



Note that both examples only work with filenames without spaces.



For files with spaces:



$ for i in *.fastq; do echo -ne "$i"; done | xargs -0 -n2





share|improve this answer


























  • Note that redirecting this to a new file would include the name of that file in the output.

    – Kusalananda
    3 hours ago











  • Thanks @Kusalananda, fixed by workaround. I guess it's time for bed.

    – Freddy
    2 hours ago














2












2








2







Maybe



$ ls *.fastq | xargs -n2
Bar_R1.fastq Bar_R2.fastq
Bar_R3.fastq Foo_R1.fastq
Foo_R2.fastq Foo_R3.fastq
Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


or for column output



$ ls *.fastq | xargs -n2 | column -t
Bar_R1.fastq Bar_R2.fastq
Bar_R3.fastq Foo_R1.fastq
Foo_R2.fastq Foo_R3.fastq
Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


(add >> file.txt to the command to append the output to the file)



Note that both examples only work with filenames without spaces.



For files with spaces:



$ for i in *.fastq; do echo -ne "$i"; done | xargs -0 -n2





share|improve this answer















Maybe



$ ls *.fastq | xargs -n2
Bar_R1.fastq Bar_R2.fastq
Bar_R3.fastq Foo_R1.fastq
Foo_R2.fastq Foo_R3.fastq
Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


or for column output



$ ls *.fastq | xargs -n2 | column -t
Bar_R1.fastq Bar_R2.fastq
Bar_R3.fastq Foo_R1.fastq
Foo_R2.fastq Foo_R3.fastq
Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq


(add >> file.txt to the command to append the output to the file)



Note that both examples only work with filenames without spaces.



For files with spaces:



$ for i in *.fastq; do echo -ne "$i"; done | xargs -0 -n2






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 hours ago

























answered 3 hours ago









FreddyFreddy

2,157210




2,157210













  • Note that redirecting this to a new file would include the name of that file in the output.

    – Kusalananda
    3 hours ago











  • Thanks @Kusalananda, fixed by workaround. I guess it's time for bed.

    – Freddy
    2 hours ago



















  • Note that redirecting this to a new file would include the name of that file in the output.

    – Kusalananda
    3 hours ago











  • Thanks @Kusalananda, fixed by workaround. I guess it's time for bed.

    – Freddy
    2 hours ago

















Note that redirecting this to a new file would include the name of that file in the output.

– Kusalananda
3 hours ago





Note that redirecting this to a new file would include the name of that file in the output.

– Kusalananda
3 hours ago













Thanks @Kusalananda, fixed by workaround. I guess it's time for bed.

– Freddy
2 hours ago





Thanks @Kusalananda, fixed by workaround. I guess it's time for bed.

– Freddy
2 hours ago













0














Using the solution you already have, it's just a matter of not specifying the filename prefix Vegan:



for file in *_R1.fastq; do
printf '%s %sn' "$file" "${file%_R1.fastq}_R2.fastq"
done >file.txt


Using printf and redirecting after the loop instead of for each output command is just my personal preference.



For the given filenames, this generates file.txt with



Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq





share|improve this answer
























  • Yes this would work with the data I supplied. However, this would not work if the files were not named in a consistent manner.

    – Jamie Alfieri
    2 hours ago











  • @JamieAlfieri Do give an example of that, because there is none in the question.

    – Kusalananda
    2 hours ago


















0














Using the solution you already have, it's just a matter of not specifying the filename prefix Vegan:



for file in *_R1.fastq; do
printf '%s %sn' "$file" "${file%_R1.fastq}_R2.fastq"
done >file.txt


Using printf and redirecting after the loop instead of for each output command is just my personal preference.



For the given filenames, this generates file.txt with



Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq





share|improve this answer
























  • Yes this would work with the data I supplied. However, this would not work if the files were not named in a consistent manner.

    – Jamie Alfieri
    2 hours ago











  • @JamieAlfieri Do give an example of that, because there is none in the question.

    – Kusalananda
    2 hours ago
















0












0








0







Using the solution you already have, it's just a matter of not specifying the filename prefix Vegan:



for file in *_R1.fastq; do
printf '%s %sn' "$file" "${file%_R1.fastq}_R2.fastq"
done >file.txt


Using printf and redirecting after the loop instead of for each output command is just my personal preference.



For the given filenames, this generates file.txt with



Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq





share|improve this answer













Using the solution you already have, it's just a matter of not specifying the filename prefix Vegan:



for file in *_R1.fastq; do
printf '%s %sn' "$file" "${file%_R1.fastq}_R2.fastq"
done >file.txt


Using printf and redirecting after the loop instead of for each output command is just my personal preference.



For the given filenames, this generates file.txt with



Paleo_R1.fastq Paleo_R2.fastq
Vegan_R1.fastq Vegan_R2.fastq






share|improve this answer












share|improve this answer



share|improve this answer










answered 3 hours ago









KusalanandaKusalananda

143k18267445




143k18267445













  • Yes this would work with the data I supplied. However, this would not work if the files were not named in a consistent manner.

    – Jamie Alfieri
    2 hours ago











  • @JamieAlfieri Do give an example of that, because there is none in the question.

    – Kusalananda
    2 hours ago





















  • Yes this would work with the data I supplied. However, this would not work if the files were not named in a consistent manner.

    – Jamie Alfieri
    2 hours ago











  • @JamieAlfieri Do give an example of that, because there is none in the question.

    – Kusalananda
    2 hours ago



















Yes this would work with the data I supplied. However, this would not work if the files were not named in a consistent manner.

– Jamie Alfieri
2 hours ago





Yes this would work with the data I supplied. However, this would not work if the files were not named in a consistent manner.

– Jamie Alfieri
2 hours ago













@JamieAlfieri Do give an example of that, because there is none in the question.

– Kusalananda
2 hours ago







@JamieAlfieri Do give an example of that, because there is none in the question.

– Kusalananda
2 hours ago












Jamie Alfieri is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Jamie Alfieri is a new contributor. Be nice, and check out our Code of Conduct.













Jamie Alfieri is a new contributor. Be nice, and check out our Code of Conduct.












Jamie Alfieri is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f515330%2fprint-multiple-filenames-to-specific-lines-in-txt-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...