parse lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parse lines
# 1  
Old 02-23-2012
parse lines

I have file which is having 500 lines. I want to get the first 100 lines then sleep, then again next 100 lines sleep so now till the end of the file.

Can someone tell me in perl and bash.

also i want to do it in threads.

Thanks..
# 2  
Old 02-23-2012
Code:
 
awk '{if(NR%100){system("sleep 2")}}1' inputfile.txt

# 3  
Old 02-23-2012
Above code is getting sleep each line, i want it to sleep after 100 lines of output, and then sleep and then output next 100 lines etc.
# 4  
Old 02-23-2012
Quote:
Originally Posted by Anjan1
Above code is getting sleep each line, i want it to sleep after 100 lines of output, and then sleep and then output next 100 lines etc.
With a slight modification of the code of itkamaraj:
Code:
awk '{if(!(NR%100)){system("sleep 2")}}1' inputfile.txt

These 2 Users Gave Thanks to Franklin52 For This Post:
# 5  
Old 02-23-2012
Thanks it works. Can someone tell me how to do it in perl

---------- Post updated at 07:21 AM ---------- Previous update was at 07:09 AM ----------

Franklin52 can u tell me what NR% means in awk statement?

I found how do it in perl
# 6  
Old 02-23-2012
Quote:
Originally Posted by Anjan1
Thanks it works. Can someone tell me how to do it in perl

---------- Post updated at 07:21 AM ---------- Previous update was at 07:09 AM ----------

Franklin52 can u tell me what NR% means in awk statement?

I found how do it in perl

NR is Special Variable in AWK which means Number of Line the process is on. Hence
Code:
NR%100

will give you the remainder of NR/100. So here, if NR is 101, the NR%100 will give 1 which will invalidate !(NR%100)
# 7  
Old 02-23-2012
Ok thanks, got it
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to parse multiple lines

What is the correct syntax to have the awk parse the next line as well? The next in bold is where I think it should go, but I wanted to ask the experts since I am a beginner. The file to be parsed is attached as well. Thank you :). awk 'NR==2 {split($2,a,"");b=substr(a,1,length(a-1));print... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Emergency UNIX and Linux Support

[Solved] AWK to parse adjacent matching lines

Hi, I have an input file like F : 0.1 : 0.002 P : 0.3 : 0.004 P : 0.5 : 0.008 P : 0.1 : 0.005 L : 0.05 : 0.02 P: 0.1 : 0.006 P : 0.01 : 0.08 F : 0.02 : 0.08 Expected output: (2 Replies)
Discussion started by: vasanth.vadalur
2 Replies

3. UNIX for Dummies Questions & Answers

How to parse 2 particular lines from Command output

Hi All, I need help on the following req. I am getting output of a command as follows: 16377612 total memory 3802460 used memory 2827076 active memory 681948 inactive memory 12575152 free memory 477452 buffer memory I want to compute used... (1 Reply)
Discussion started by: mailsara
1 Replies

4. Shell Programming and Scripting

Parse out specific lines

Hello, For the life of me, I can't figure out how to extract only certain lines of a file. For example, the file contains: project.max-sem-ids privileged 1.02K - deny - system 16.8M max deny ... (2 Replies)
Discussion started by: PointyWombat
2 Replies

5. Shell Programming and Scripting

Parse a file to display lines containing a word

Hi! I'm trying to create a shell script to parse a file which might have multiple lines matching a pattern (i.e. containing some word). I need to return all lines matching the pattern, but stripping the contents of that line until the pattern is matched For example, if my input file was ... (4 Replies)
Discussion started by: orno
4 Replies

6. Shell Programming and Scripting

Parse and delete lines efficiently

Hi I have a set of options in the form of key value in a file. Need to find a particular value of 'a' and delete all lines till the next 'a' keyword . Ex : a bbb c ddd e fff g hhh a sss c ggg e xxx f sss a ddd d sss r sss g hhh (5 Replies)
Discussion started by: TDUser
5 Replies

7. Shell Programming and Scripting

Extra/parse lines from a file between unque lines through the file

I need help to parse a file where there are many records, all of which are consistently separated by lines containing “^=============” and "^ End of Report". Example: ============= 1 2 3 4 End of record ============= 1 3 4 End of record Etc.... I only need specific lines... (5 Replies)
Discussion started by: jouuu
5 Replies

8. Shell Programming and Scripting

Parse and count lines

I have a data file in the following format (refer to input file) with multiple lines containing some information. I need an output file to loop thorough the input file with summarized information as seen below (refer to output file) ‘Date Time' and ‘Beta Id' input file values should be concatenated... (7 Replies)
Discussion started by: shekharaj
7 Replies

9. Shell Programming and Scripting

parse of lines with different delimiters

Hi, I am having huge file with the following lines. 2007:10:01:00:00:49:GMT: subject=BMRA.BM.T_ABTH7.FPN, message={SD=2007:10:01:00:00:00:GMT,SP=5,NP=2,TS=2007:10:01:01:00:00:GMT,VP=0.0,TS=2007:10:01:01:30:00:GMT,VP=0.0} 2007:10:01:00:00:49:GMT: subject=BMRA.BM.T_ABTH7G.FPN,... (9 Replies)
Discussion started by: nathasha
9 Replies

10. UNIX for Dummies Questions & Answers

parse multiple lines? should be a easy answer...

inputfile: A B C D E F G H 1 2 3 4 ----------- I want to read these and put them into a variable: file=../inputfile col2line1=`cat $file | awk '{print $2}'` how do i extract row 2's E,F,G,H or row 3's 1,2,3,4??? I tried the search, didn't get much, maybe i suck at searching too... (4 Replies)
Discussion started by: DeuceLee
4 Replies
Login or Register to Ask a Question