{"id":457,"date":"2010-03-16T16:24:07","date_gmt":"2010-03-16T16:24:07","guid":{"rendered":"http:\/\/soi57.net\/blog\/?p=457"},"modified":"2010-03-16T16:24:07","modified_gmt":"2010-03-16T16:24:07","slug":"bash-leer-fichero-linea-por-linea","status":"publish","type":"post","link":"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/","title":{"rendered":"Bash: leer fichero linea por linea"},"content":{"rendered":"<p>Aunque es una tonter\u00eda, hoy me volvi loco porque ten\u00eda que hacer un <strong>script en bash<\/strong> que parseara un archivo <strong>linea por linea<\/strong>. El problema que tenia era que cada linea tenia palabras y estas estaban <strong>separadas por espacios en blanco<\/strong>. Entonces al hacer un bucle for me pon\u00eda una palabra por linea, es decir si el archivo tenia este contenido:<\/p>\n<blockquote><p>Esto es una linea<br \/>\nEsto es otra<br \/>\nY esta es la ultima<\/p>\n<p>for line in $(cat fichero_lineas.txt); do echo \u00ab$linea\u00bb ; done<\/p>\n<p>Esto<br \/>\nes<br \/>\nuna<br \/>\nlinea<br \/>\nEsto<br \/>\nes<br \/>\notra<br \/>\nY<br \/>\nesta<br \/>\nes<br \/>\nla<br \/>\nultima\n<\/p><\/blockquote>\n<p>Encontr\u00e9 dos <strong>soluciones<\/strong>: <\/p>\n<p>Una es usar un <strong>blucle while<\/strong> e ir leyendo <strong>l\u00ednea por l\u00ednea<\/strong> con read.<\/p>\n<blockquote><p>#!\/bin\/bash<\/p>\n<p>while read linea; do<br \/>\n    echo $linea<br \/>\ndone < $1<\/p><\/blockquote>\n<p>La otra es cambiar el valor de la <strong>variable IFS<\/strong>, que es el separador de campo. Por ejemplo IFS=&#8217;\\n&#8217; que es el retorno de carro.<\/p>\n<blockquote><p>IFS=&#8217;\\n&#8217;<br \/>\nfor i in $(cat $1)<br \/>\ndo<br \/>\n    echo $i<br \/>\ndone<\/p><\/blockquote>\n<div style='text-align:left' class='yasr-auto-insert-visitor'><\/div>","protected":false},"excerpt":{"rendered":"<p>Aunque es una tonter\u00eda, hoy me volvi loco porque ten\u00eda que hacer un script en bash que parseara un archivo linea por linea. El problema que tenia era que cada &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"yasr_overall_rating":0,"yasr_post_is_review":"","yasr_auto_insert_disabled":"","yasr_review_type":"","footnotes":""},"categories":[801],"tags":[],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-no-index"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Bash: leer fichero linea por linea<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bash: leer fichero linea por linea\" \/>\n<meta property=\"og:description\" content=\"Aunque es una tonter\u00eda, hoy me volvi loco porque ten\u00eda que hacer un script en bash que parseara un archivo linea por linea. El problema que tenia era que cada &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/\" \/>\n<meta property=\"og:site_name\" content=\"Android, administracion de sistemas y seo\" \/>\n<meta property=\"article:published_time\" content=\"2010-03-16T16:24:07+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/soi57.net\/blog\/#\/schema\/person\/9410e0a8d6f61a74f9f82f2229ab79d7\"},\"headline\":\"Bash: leer fichero linea por linea\",\"datePublished\":\"2010-03-16T16:24:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/\"},\"wordCount\":169,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/soi57.net\/blog\/#organization\"},\"articleSection\":[\"No Index\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/\",\"url\":\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/\",\"name\":\"Bash: leer fichero linea por linea\",\"isPartOf\":{\"@id\":\"https:\/\/soi57.net\/blog\/#website\"},\"datePublished\":\"2010-03-16T16:24:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"https:\/\/soi57.net\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash: leer fichero linea por linea\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/soi57.net\/blog\/#website\",\"url\":\"https:\/\/soi57.net\/blog\/\",\"name\":\"Android, administracion de sistemas y seo\",\"description\":\"soi57.net\/blog\",\"publisher\":{\"@id\":\"https:\/\/soi57.net\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/soi57.net\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/soi57.net\/blog\/#organization\",\"name\":\"Soi57.Net\",\"url\":\"https:\/\/soi57.net\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/soi57.net\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/soi57.net\/blog\/wp-content\/logo_soi57.net_half.jpg\",\"contentUrl\":\"https:\/\/soi57.net\/blog\/wp-content\/logo_soi57.net_half.jpg\",\"width\":342,\"height\":77,\"caption\":\"Soi57.Net\"},\"image\":{\"@id\":\"https:\/\/soi57.net\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/soi57.net\/blog\/#\/schema\/person\/9410e0a8d6f61a74f9f82f2229ab79d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/soi57.net\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6e87f10096d6c8f82a9bc2ddc0f3a223?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6e87f10096d6c8f82a9bc2ddc0f3a223?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/soi57.net\"]},false]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bash: leer fichero linea por linea","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/","og_locale":"es_ES","og_type":"article","og_title":"Bash: leer fichero linea por linea","og_description":"Aunque es una tonter\u00eda, hoy me volvi loco porque ten\u00eda que hacer un script en bash que parseara un archivo linea por linea. El problema que tenia era que cada &hellip;","og_url":"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/","og_site_name":"Android, administracion de sistemas y seo","article_published_time":"2010-03-16T16:24:07+00:00","author":"root","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/#article","isPartOf":{"@id":"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/"},"author":{"name":"root","@id":"https:\/\/soi57.net\/blog\/#\/schema\/person\/9410e0a8d6f61a74f9f82f2229ab79d7"},"headline":"Bash: leer fichero linea por linea","datePublished":"2010-03-16T16:24:07+00:00","mainEntityOfPage":{"@id":"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/"},"wordCount":169,"commentCount":1,"publisher":{"@id":"https:\/\/soi57.net\/blog\/#organization"},"articleSection":["No Index"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/","url":"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/","name":"Bash: leer fichero linea por linea","isPartOf":{"@id":"https:\/\/soi57.net\/blog\/#website"},"datePublished":"2010-03-16T16:24:07+00:00","breadcrumb":{"@id":"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/soi57.net\/blog\/bash-leer-fichero-linea-por-linea\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"https:\/\/soi57.net\/blog\/"},{"@type":"ListItem","position":2,"name":"Bash: leer fichero linea por linea"}]},{"@type":"WebSite","@id":"https:\/\/soi57.net\/blog\/#website","url":"https:\/\/soi57.net\/blog\/","name":"Android, administracion de sistemas y seo","description":"soi57.net\/blog","publisher":{"@id":"https:\/\/soi57.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/soi57.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/soi57.net\/blog\/#organization","name":"Soi57.Net","url":"https:\/\/soi57.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/soi57.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/soi57.net\/blog\/wp-content\/logo_soi57.net_half.jpg","contentUrl":"https:\/\/soi57.net\/blog\/wp-content\/logo_soi57.net_half.jpg","width":342,"height":77,"caption":"Soi57.Net"},"image":{"@id":"https:\/\/soi57.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/soi57.net\/blog\/#\/schema\/person\/9410e0a8d6f61a74f9f82f2229ab79d7","name":"root","image":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/soi57.net\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6e87f10096d6c8f82a9bc2ddc0f3a223?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6e87f10096d6c8f82a9bc2ddc0f3a223?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/soi57.net"]},false]}},"yasr_visitor_votes":{"stars_attributes":{"read_only":false,"span_bottom":false},"number_of_votes":0,"sum_votes":0},"_links":{"self":[{"href":"https:\/\/soi57.net\/blog\/wp-json\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soi57.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soi57.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soi57.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soi57.net\/blog\/wp-json\/wp\/v2\/comments?post=457"}],"version-history":[{"count":1,"href":"https:\/\/soi57.net\/blog\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":458,"href":"https:\/\/soi57.net\/blog\/wp-json\/wp\/v2\/posts\/457\/revisions\/458"}],"wp:attachment":[{"href":"https:\/\/soi57.net\/blog\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soi57.net\/blog\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soi57.net\/blog\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}