|
Suppose to feed the filter standard input with these line:
line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 line 10
It would be nicer if someone tell me how to write a script that prints only every 4 lines, in the case of the example input...
Started by Andrea Francia on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Awk '{ if ((NR-1) %4 ==0) print}'
awk 'NR%4 == 1 {print}'</etc/hosts
Replace 4 by whatever value you want of course. .
Yes | cat -n | head -10 | awk 'NR % 4 == 1' 1 y 5 y 9 y
That is, your answer is " awk 'NR % 4 == 1' " .
|
|
I'm parsing a large file in Perl line-by-line (terminated by \n), but when I reach a certain keyword, say "TARGET", I need to grab all the lines between TARGET and the next completely empty line.
So, given a segment of a file:
Line 1
Line 2
Line 3
Line...
Started by ImSleeping on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
']'; __DATA__ Line 1 Line 2 Line 3 Line 4 Target Line 5 Grab this line Line 6 Grab this line Next Line
Edit Line 2 Line 3 Line 4 Target Line 5 Grab this....
|
|
Hello,
I'm parsing a source code file, and I want to remove all line comments (i.e. starting with "//") and multi-line comments (i.e. / .... /). However, if the multi-line comment has at least one line-break in it (\n), I want the output to have exactly...
Started by Rax Olgud on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Added....
"line" "line 6" "line 7" "line ??" "line ??"
Edits:
Updated to new specification.
" /\n" ...
" \n" ...
"line 7 / \n" ...
"/* comment */line 6\n" ...
Of a comment*/ line 5\n" ...
|
Ask your Facebook Friends
|
In deploying a new version of our ASP.NET application, we need to set the authentication method for a particular page to be "Integrated only." We can do this from the IIS managment console, but would like to write a script (batch or powershell, doesn'...
Started by Brien on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at serverfault):
Alternatively, you could check out the System.DirectoryServices API for IIS 5 & 6 ( http.
|
|
The closest I've seen in the PHP docs, is to fread() a given length, but that doesnt specify which line to start from. Any other suggestions?
Started by lock on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
So you will have to read from the start....
Lt;?php $f = fopen('sample.txt', 'r'); $lineNo = 0; $startLine = 3; $endLine = 6; while ($lineYou not going to be able to read starting from line X because lines can be of arbitrary length.
|
|
Hi programmers,
I want read line by line a Unicode (UTF-8) text file created by Notepad, i don't want display the Unicode string in the screen, i want just read and compare the strings!.
This code read ANSI file line by line, and compare the strings
What...
Started by Freeseif on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
I]); } // 110 10 else if(input[i] < 0x800) { result[cindex++] = ((char)(MASK2BYTES | input[i] >> 6++] = ((char)(MASKBYTE | input[i] >> 6 & MASKBITS)); result[cindex++] = ((char)(MASKBYTE | input[rindex] & 0x0F) << 1....
|
|
I searched SO for a similar Q/A to no avail. I want to shuffle the lines of a text file randomly and create a new file. The file may have several thousands of lines.
How can I do that with cat, awk, cut, etc.?
Started by Amaç Herdağdelen on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
In effect, the lines } } }' file
output
$ cat file 1 2 3 4 5 6 7 8 9 10 $ ./shell.sh 7 5 10 9 6 8 2 1 3 4
I use a tiny perl.
To each line, sorts them and then strips the random number from each line.
|
|
From a related question asked by Bi, I've learnt how to print a matching line together with the line immediately below it. The code looks really simple:
#!perl open(FH,'FILE'); while ($line = <FH>) { if ($line =~ /Pattern/) { print "$line"; print...
Started by Mike on
, 9 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
You always want to store the last line that you saw in case the next line has your pattern and you $last = ""; while (my $line = <FH>) { if ($line =~ /Pattern/) { print $last; print $line; print scalar <FH>....
|
|
I got inspired to try out Haskell again based on a recent answer . My big block is that reading a file line by line (a task made simple in languages such as Perl) seems complicated in a functional language. How do you read a file line by line in your ...
Started by Jon Ericson on
, 54 posts
by 48 people.
Answer Snippets (Read the full thread at stackoverflow):
Ephemient....
Not fileReader.EoF 5 Dim line As String = fileReader.ReadLine() 6 Debug.WriteLine(String.Format("{0}: {1 a lot of reading to discover that show converted the line numbers into a form I could concatenate to the line.
|
|
I'm trying to figure out the proper PBP approved way to process a multi line string one line at a time. Many Perl coders suggest treating the multi line string as a filehandle, which works fine unless you have "use strict" in your script. Then you get...
Started by Kurt W. Leucht on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Convert the multi-line string into a list of single line strings with split :
my @resultLines This Is A Test}; while( $data =~ /(.+)$/mg) { print "line is '$1'\n"; }
This is slightly less.
|