NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Ejercicio 8

// Required external modules.
fs = require('fs');
path = require('path');

bb = require('bluebird');

os = require('os'); // Needed for the end-of-line constant, in order to be ed54dd822d4ba184e018f67ff52381b744959c77
// system-independent.

// Get a copy of the arguments array.
var argv = process.argv;
// Get the name of this JavaScript file, without the extension.
var scriptName = path.basename(argv[1], ".js");

/*************************************************************************/
/* Auxiliary functions. */
/*************************************************************************/

function contentsToArray(contents) {
// Converts the contents of the file into an array of text lines.
// Returns the array.
return contents.split(os.EOL);
}
function parseArray(contents,pattern) {
// Parse each array slot (i.e., each text line).
for(var i in contents) {
// If such line has the "pattern" as a substring...
// Note that search() returns the position of its argument
// in the string where it is used. If it is not found,
// search() returns -1.
if (contents[i].search(pattern) > -1)
// Prints it to standard output.
console.log("%d: %s", parseInt(i)+1, contents[i]);
}
}
function processFile(data,pattern) {
// Converts the file into an array of text lines and parses it,
// looking for the pattern given in the second argument.
parseArray(contentsToArray(data),pattern);
}

/*************************************************************************/
/* Main programme. */
/*************************************************************************/
// Check whether the needed arguments have been received or not.
if (argv.length<4) {
// If not, print usage instructions and exit.
console.log("Usage: node " + scriptName + " pattern file");
console.log("Print all lines of 'file' that contain" +
" the 'pattern' substring.");
process.exit();
}
function onCauseError(err) { console.log("Please use the name of an existant file!!"); }
function onSuccess(n) {
return function (res){
console.log('n---------------------nDocumento '+argv[n]+', numero de arg '+n+'n---------------------');
processFile(res,argv[2]);
}
}

console.log('Iniciando programa');
var docs = argv.length-3;
console.log('El numero de documentos son '+docs);

var read_promise = bb.promisify(fs.readFile);
for(i = 3; i<argv.length; i++){
read_promise(argv[i], "utf8").then(onSuccess(i), onCauseError);
}


//fs.readFile(argv[3], "utf8", function(err,data){
// if (err) {
// console.log("Please use the name of an existant file!!");
// } else {
// processFile(data,argv[2]);
// }
//})
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.