The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script that extract some lines from a file lookin into another heartwork Shell Programming and Scripting 7 01-25-2008 06:57 AM
How to extract a sequence of n lines from a file 0ktalmagik Shell Programming and Scripting 4 06-29-2006 11:24 PM
How to extract many lines from a file, typically the 1000 last kingkong UNIX for Dummies Questions & Answers 3 11-23-2005 04:20 AM
how to extract a range of lines from a file beilstwh Shell Programming and Scripting 5 07-09-2004 08:20 AM
extract specific lines from file apalex UNIX for Dummies Questions & Answers 2 05-15-2001 09:57 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-16-2006
alexcol alexcol is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 31
Cool Extract lines from a file automatically. Please a Help

hello, hope you can help me:
ive got a file called archivos

The content or structure of this file is

./chu0/filechu
./chu1/filechu

I extract each line from this file manually and redirect to a file, and it Works fine, so the command line is:

awk ‘/chu0/ {print $0}’ < archivos > portal0
awk ‘/chu1/ {print $0}’ < archivos > portal1

The problem is to extract these lines automatically, an i dont know how to do this, with a loop for example.

and i tried but gets some error whit this command

i=0
while (i<=num)
do
awk –v i=$i ‘ /chu$i/ {print $0} < archivos > portal$i
done

how can i do that so i can extract lines from this file automatically?can you help me? please.
  #2 (permalink)  
Old 12-16-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
#!/bin/ksh

while read myLine
do
  echo "line-> [${myLine}]"
done < archivos
  #3 (permalink)  
Old 12-16-2006
alexcol alexcol is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 31
Cool ok. im working with born shell, how the code woul be, since i dont know about korn

Thanks for yor reply, but in this script how the code will be in born shell.?
  #4 (permalink)  
Old 12-16-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
try it as 'bourne' and see what happens.
  #5 (permalink)  
Old 12-16-2006
alexcol alexcol is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 31
Cool it didnt work

This code lnly print the output on the screen:

line-> [./chu0/filechu]
line-> [./chu1/filechu]

But, i want is to redirect the content of each line to a file
i.e. file0 the content must be ./chu0/filechu
and file1 the content must be ./chu1/filechu
thanks
  #6 (permalink)  
Old 12-16-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
#!/bin/sh
i=0
while read myLine
do
  echo "${myLine}" > "file${i}"
  i=`expr $i + 1`
done < archivos
  #7 (permalink)  
Old 12-16-2006
alexcol alexcol is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 31
Cool oh. Great. it works. Thanks, and pardon me but i wish i could understand each line

Could you please comment each line what it does?. i am new at unix, why you quote some lines.
Thanks again.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0