Process selected lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process selected lines
# 1  
Old 02-25-2010
Process selected lines

I have an if statement where I state that if there are more than one records (lines) found containing a string in a file, then it enters into a while loop to use each line for as many lines as there are and then stop.

Trouble is, I can't figure out how to move to the next instance of each line. I would have thought sed or awk would happily (and easily) have a solution for it, but it seems that is not the case. So far example:

1,record one,data0
2,record two,data0
3,record three,data1

In the case above, I search for "data1", and find only one record so I use and move on. But if I search for data0, then I need firstly to use the first line found containing data0 which could be anywhere and not on any specific line number, then loop back to use the second in the same way within the while loop. How do I move to the second is what I can't figure out?

Thanks
Derek.
# 2  
Old 02-25-2010
What excatly, you are trying to achieve here? Perhapes, you should use an array in awk with data0_an incremental integer as an index.


cheers,
Devaraj Takhellambam
# 3  
Old 02-25-2010
The key thing is doing something different with the second instance than the first, which is why I'm trying to find a way to move straigth to the nth found instance.

Is there anything more straigthforward where you can grep a file, and do something with the second line you find?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use same file selected in first bash process that has matching digits in it fot the second

In the below portion of a bash script the user selects a file from a directory. select file in $(cd /home/cmccabe/Desktop/NGS/API/5-14-2016/bedtools;ls);do break;done files in directory 123_base_counts.txt 456_base_counts.txt 789_base_counts.txt second portion of bash currently (user... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Deleting selected lines in a file

Hi Guys , I have two files say a1 and a2 having following contents a1 dag wfd a2 dag wfd chire hcm I want to delete only the lines in a2 which are in a1 and final output of a2 should be a2 chire hcm (6 Replies)
Discussion started by: Pradeep_1990
6 Replies

3. Shell Programming and Scripting

Selected matching lines

two files: one with the line number only, and the 2nd one with line number and content, as following: line_file.txt 1 3 5 9 23 30 content_file.txt 1|we are the world|good|great 2|easily do this by highlighting you|easily do this by highlighting you|easily do this by highlighting... (2 Replies)
Discussion started by: dtdt
2 Replies

4. Shell Programming and Scripting

Delete selected lines

hi Gurus, I have a source file with more than 10 columns ( not fixed ) I want to delete all the lines on the following condition 1) where i have first column as "UPDATE PLAN ADD RATE SCHEDULE" and fourth column as null awk '($1=="UPDATE PLAN ADD RATE SCHEDULE" && $4=="") {print $0}'... (5 Replies)
Discussion started by: r_t_1601
5 Replies

5. Shell Programming and Scripting

finding least out of selected lines

Hello, I have a file, which looks like: I want to print the row containg "PRO" in second column after comparing and finding the minimum value of fifth column present in all "PRO". and likewise for every other string present in second column. I am using : filename=list... (2 Replies)
Discussion started by: CAch
2 Replies

6. Shell Programming and Scripting

trying to print selected fields of selected lines by AWK

I am trying to print 1st, 2nd, 13th and 14th fields of a file of line numbers from 29 to 10029. I dont know how to put this in one code. Currently I am removing the selected lines by awk 'NR==29,NR==10029' File1 > File2 and then doing awk '{print $1, $2, $13, $14}' File2 > File3 Can... (3 Replies)
Discussion started by: ananyob
3 Replies

7. UNIX for Dummies Questions & Answers

Copy selected lines in vim

Hi, I am looking to copy selected lines from a file using the vim editor. I have looked up a few resources and they have suggested to use this- Type mk Type: "ay'k (double quotes, <register name from a-z>, <y-yank single quote, k You can paste those lines wherever you want with "ap I tried... (7 Replies)
Discussion started by: coolavi
7 Replies

8. UNIX for Dummies Questions & Answers

how to cut selected 10k lines continuosly

I have a source file having 20lacs lines i want to cut first 1 lac lines from source file and redirect to other file (i.e after redirecting the output to other file the source file should have only 19 lacs count ). Pls help me in getting solution. Thanks in advance. (9 Replies)
Discussion started by: vamshi
9 Replies

9. UNIX for Dummies Questions & Answers

extracting selected few lines through perl

How can I extract few lines(like 10 to 15, top 10 and last 10) from a file using perl. I do it with sed, head and tail in unix scripting. I am new to perl. Appreciate your help. (2 Replies)
Discussion started by: paruthiveeran
2 Replies

10. Shell Programming and Scripting

print selected lines

Hi everybody: I try to print in new file selected lines from another file wich depends on the first column. I have done a script like this: lines=( "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "21" "31" "41" "51" "55" "57" "58" ) ${lines} for lines in ${lines} do awk -v ... (6 Replies)
Discussion started by: tonet
6 Replies
Login or Register to Ask a Question