Extract lines from a file automatically. Please a Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract lines from a file automatically. Please a Help
# 1  
Old 12-16-2006
Tools 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  
Old 12-16-2006
Code:
#!/bin/ksh

while read myLine
do
  echo "line-> [${myLine}]"
done < archivos

# 3  
Old 12-16-2006
Tools 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  
Old 12-16-2006
try it as 'bourne' and see what happens.
# 5  
Old 12-16-2006
Tools 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  
Old 12-16-2006
Code:
#!/bin/sh
i=0
while read myLine
do
  echo "${myLine}" > "file${i}"
  i=`expr $i + 1`
done < archivos

# 7  
Old 12-16-2006
Tools 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract lines that have entries in VI file

Dears experts i have UNIX file that contain 4 million lines , i need to extract all lines that have entiries saved in VI file , i have below comand but it takes tooooo long time : for i in `cat file1.csv`; do cat dump | grep -i $i >> file2.csv; done where : file1.csv = VI file that... (12 Replies)
Discussion started by: is2_egypt
12 Replies

2. Shell Programming and Scripting

Extract lines from a file

Hi all; Here is my file which contains a list of files (recent versions of files are in red). This file is dynamic, files versions can change at any time (versions can increment) filename ------------------------------------------------------- ... (8 Replies)
Discussion started by: chercheur111
8 Replies

3. Shell Programming and Scripting

How to extract certain lines from a file?

Hi guys I have a several thousands line file in the following format: n817 -------------------------------------------------- n842 -------------------------------------------------- n877 -------------------------------------------------- n513 /bb/data/rmt2db.lrl:JBSKDB 31915 75... (4 Replies)
Discussion started by: aoussenko
4 Replies

4. Shell Programming and Scripting

Extract particular lines from a file

Hi all, I have a file with many records with information as given below ID A16L2_HUMAN Reviewed; 619 AA. AC Q8NAA4; A5PL30; B2RPK5; Q658V4; Q6PID3; Q8NBG0; DT 20-MAY-2008, integrated into UniProtKB/Swiss-Prot. DT 20-MAY-2008, sequence version 2. DT ... (1 Reply)
Discussion started by: kaav06
1 Replies

5. Shell Programming and Scripting

how to write bash script that will automatically extract zip file

i'm trying to write a bash script that that will automatically extract zip files after the download. i writed this script #!/bin/bash wget -c https://github.com/RonGokhle/kernel-downloader/zipball/master CURRENDIR=/home/kernel-downloader cd $CURRENDIR rm $CURRENDIR/zipfiles 2>/dev/null ... (2 Replies)
Discussion started by: ron gokhle
2 Replies

6. Shell Programming and Scripting

Extract some lines from one file and add those lines to current file

hi, i have two files. file1.sh echo "unix" echo "linux" file2.sh echo "unix linux forums" now the output i need is $./file2.sh unix linux forums (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

7. Shell Programming and Scripting

script that will automatically extract

how do i write a script that will automatically extract rar files after the download in a particular folder? can you give me an idea please? :D or is there an existing script for this? (3 Replies)
Discussion started by: garfish
3 Replies

8. Shell Programming and Scripting

extract particular lines from text file

I have two files file A which have a number in every row and file B which contains few hundred thousand rows with about 300 characters in each row (csv) What I need is to extract whole rows from B file (only these which numbers are indicated in A file) I also need to use cygwin. Any... (7 Replies)
Discussion started by: gunio
7 Replies

9. Shell Programming and Scripting

add lines automatically based on a field on another file

hello I have a number of lines that need to be added at the end of a file each time I add a field in another file (let's name it file2) file2 has this format: filed1:field2:path1:path2:path3:path... Whenever I add a path field, I should add to file1 these lines: <Location path1>... (0 Replies)
Discussion started by: melanie_pfefer
0 Replies

10. UNIX for Dummies Questions & Answers

extract specific lines from file

hi, how would i extract a range of lines in a file by using the line number? ex: file contains: 1 title 2 i want 3 this part 4 to be taken out 5 from this file 6 and sent to 7 another file 8 not needed 9 end of file In this case, i want to copy line number 2 to 7 on a new... (2 Replies)
Discussion started by: apalex
2 Replies
Login or Register to Ask a Question