command for signing up with a collection of documents with each other

I have ...

me @computer system :~/ gutenberg/euclid$ ls

book01.html book04.html book07.html book10.html book13.html book02.html book05.html book08.html book11.html book03.html book06.html book09.html book12.html

and also I intend to sign up with all these.html documents right into the very same large documents, in order. What command or command series can I make use of?

2019-12-02 03:12:23
Source Share
Answers: 4

The straightforward remedy will possibly function, if your internet browser is permissiv.

cat book[0-9]*.html > book.html

Sure you can walk around removing things to be possibly a little extra lawful :

perl -e 'undef($/); for($x=0;$x<=$#ARGV;$x++) { open(X,"<",$ARGV[$x]); $_ = <X>; close(X); s/.*<body[^>]*>//s unless ($x == 0);  s|</body>|| unless ($x == $#ARGV); print;' book[0-9]*.html > book.html

But that is no warranty that you will actually have every little thing you require either, if the phases have various designs or javascript or whatever.

2019-12-03 05:07:38

In this certain instance cat book??.html > book.html will certainly function great, if you uncommitted concerning correct HTML layout.

For an extra basic instance, claim you had "book1.html" as opposed to "book01.html", "book2.html" as opposed to "book02.html" etc. The documents names do not arrange lexically the like practically. You can do something similar to this :

(echo book?.html | sort; echo book??.html | sort) | xargs cat > book.html

So as a whole : script_generating_file_names_in_order | xargs cat > all_one_file

That expression can go a lengthy means.

2019-12-03 05:07:29

I acquire the statements concerning head/tail, and also have a remedy, arranged by number without that xargs/sort/echo things.

cat book{01..12}.html book-all.html
2019-12-03 05:07:21

If you make use of GNU sort you can make use of sort -V to sort the names in the proper order :

$ echo -e "book4\nbook2\nbook17\nbook12" | sort -V

This benefits any kind of variety of documents :

ls book*.html | sort -V | xargs cat > allbooks.html
2019-12-03 05:07:18