Sponsored Content
Full Discussion: Selecting lines of a file
Top Forums Shell Programming and Scripting Selecting lines of a file Post 302461269 by puttster on Saturday 9th of October 2010 05:41:44 PM
Old 10-09-2010
Selecting lines of a file

Say I wanted to select the 5th line of a file without knowing the context of the file. Would I use grep and pipe it into wc or is there a more simple way of doing this?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with selecting specific lines in a large file

Hello, I need to select the 3 lines above as well as below a search string, including the search string. I have been trying various combinations using sed command without any success. Can anuone help please. Thanking (2 Replies)
Discussion started by: tansha
2 Replies

2. UNIX for Dummies Questions & Answers

command for selecting specific lines from a script

I need help on following script: I need to print the lines which are in bold letters in separate file as record string("|") emp_name; string("|") emp_id; decimal("|") emp_salary; string("|") emp_status; string("\n") emp_proj; end (1 Reply)
Discussion started by: gardasgangadhar
1 Replies

3. Shell Programming and Scripting

Selecting Lines on text file

Hi All, I am creating a script that sends log data from text files to a Database and I will like to read sugestions, as I think that there might be better ways to achive this than with my shell script; maybe perl or I don't know, but I will like to read some sugestions. The log is from... (10 Replies)
Discussion started by: oconmx
10 Replies

4. Shell Programming and Scripting

about selecting lines

Hello , i got text file like that' C:\Users\Public\Pictures\Sample Pictures\aa.jpg C:\Users\Public\Pictures\Sample Pictures\thumb.jpg C:\Users\Public\Pictures\vv\cc.jpg C:\Users\Public\Pictures\Sample Pictures\ee.jpg C:\Users\Public\aa\Sample Pictures\cvswsr.jpg... (1 Reply)
Discussion started by: davidkhan
1 Replies

5. Shell Programming and Scripting

Selecting lines with sed

Hi all, I have a file with special characters like this file1 691775025 ýÄqJ8^Z^Y{ 2004-08-23E P 100.00 45585025 0527541139295037342008-07-25OEP 100.00 6983025 ýB<9D>x<^F^Xb 2004-11-16SPP 100.00 I need a sed command to print the lines which don't have special characters.ie., only line 2... (9 Replies)
Discussion started by: allinshell
9 Replies

6. Shell Programming and Scripting

Selecting a range of Lines

Hi All, Is there a way to get a range of lines from a file??? I want to search through a set of scripts and need to select the group of lines which do the FTP. Say, Line1 Line2 ftp SERVER user UNAME PASS send FILE_TO_BE_SENT close Line3 Line4 Line5 ftp SERVER1 user USER1 PASS1... (6 Replies)
Discussion started by: beinthemiddle
6 Replies

7. Shell Programming and Scripting

selecting lines using awk

I have a file which contains five hundred thousand lines (500,000). I want to select lines of every 1000 lines from that file using AWK. I can think something like this in bash as below: for lines in {0..500000..1000} do ........ ........ done But I want to use AWK. I do not know how to... (4 Replies)
Discussion started by: vjramana
4 Replies

8. Shell Programming and Scripting

selecting and deleting specific lines with condition

I have a set of data as below: The first field, $1 represent "|". The $3 (3rd field) and $6 (6th field) in my data file represent "number-molecule" which has arrangement as below: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... (9 Replies)
Discussion started by: vjramana
9 Replies

9. Shell Programming and Scripting

Help with awk for selecting lines in a file avoiding repetition

Hello, I am using Awk in UBUNTU 12.04. I have a file as following with 48,432,354 lines and 4 fields. The file has this structure (There are repetitions of the first column in several lines) AB_14 S54 A G AB_14 S55 A A AB_14 S56 G G GO_15 S45 T A GO_15 S46 A A PT_16 S33 C C PT_16 ... (4 Replies)
Discussion started by: Homa
4 Replies

10. Shell Programming and Scripting

Selecting lines having same values for first two columns

Hello to all. This is first post. Kindly excuse me if I do not adhere to any rules and regulations of this forum. I have a file containing some rows with three columns each per row(separeted by a space). There are certain rows for which first two columns have same value but the value in... (6 Replies)
Discussion started by: manojmalhotra13
6 Replies
Syntax::Keyword::Gather(3pm)				User Contributed Perl Documentation			      Syntax::Keyword::Gather(3pm)

NAME
Syntax::Keyword::Gather - Provide a gather keyword VERSION
version 1.001000 SYNOPSIS
use Syntax::Keyword::Gather; my @list = gather { # Try to extract odd numbers and odd number names... for (@data) { if (/(one|three|five|seven|nine)$/) { take qq{'$_'} } elsif (/^d+$/ && $_ %2) { take $_ } } # But use the default set if there aren't any of either... take @defaults unless gathered; } or to use the stuff that Sub::Exporter gives us, try # this is a silly idea use syntax gather => { gather => { -as => 'bake' }, take => { -as => 'cake' }, }; my @vals = bake { cake (1...10) }; DESCRIPTION
Perl 6 provides a new control structure -- "gather" -- that allows lists to be constructed procedurally, without the need for a temporary variable. Within the block/closure controlled by a "gather" any call to "take" pushes that call's argument list to an implicitly created array. "take" returns the number of elements it took. This module implements that control structure. At the end of the block's execution, the "gather" returns the list of values stored in the array (in a list context) or a reference to the array (in a scalar context). For example, instead of writing: print do { my @wanted; while (my $line = <>) { push @wanted, $line if $line =~ /D/; push @wanted, -$line if some_other_condition($line); } push @wanted, 'EOF'; join q{, }, @wanted; }; instead we can write: print join q{, }, gather { while (my $line = <>) { take $line if $line =~ /D/; take -$line if some_other_condition($line); } take 'EOF'; } and instead of: my $text = do { my $string; while (<>) { next if /^#|^s*$/; last if /^__[DATA|END]__ $/; $string .= $_; } $string; }; we could write: my $text = join q{}, gather { while (<>) { next if /^#|^s*$/; last if /^__[DATA|END]__ $/; take $_; } }; There is also a third function -- "gathered" -- which returns a reference to the implicit array being gathered. This is useful for handling defaults: my @odds = gather { for @data { take $_ if $_ % 2; take to_num($_) if /[one|three|five|nine]$/; } take (1,3,5,7,9) unless gathered; } Note that -- as the example above implies -- the "gathered" function returns a special Perl 5 array reference that acts like a Perl 6 array reference in boolean, numeric, and string contexts. It's also handy for creating the implicit array by some process more complex than by simple sequential pushing. For example, if we needed to prepend a count of non-numeric items: my @odds = gather { for @data { take $_ if $_ %2; take to_num($_) if /[one|three|five|seven|nine]$/; } unshift gathered, +grep(/[a-z]/i, @data); } Conceptually "gather"/"take" is the generalized form from which both "map" and "grep" derive. That is, we could implement those two functions as: sub map (&@) { my $coderef = shift; my @list = @{shift @_}; return gather { take $coderef->($_) for (@list) }; } sub grep (&@) { my $coderef = shift; my @list = @{shift @_}; return gather { take $_ if $coderef->($_) for @list }; } A "gather" is also a very handy way of short-circuiting the construction of a list. For example, suppose we wanted to generate a single sorted list of lines from two sorted files, but only up to the first line they have in common. We could gather the lines like this: my @merged_diff = gather { my $a = <$fh_a>; my $b = <$fh_b>; while(1) { if ( defined $a && defined $b ) { if ($a eq $b) { last } # Duplicate means end of list elsif ($a lt $b) { take $a; $a = <$fh_a>; } else { take $b; $b = <$fh_b>; } } elsif (defined $a) { take $a; $a = <$fh_a>; } elsif (defined $b) { take $b; $b = <$fh_b>; } else { last } } } NAME
Syntax::Keyword::Gather - Implements the Perl 6 'gather/take' control structure in Perl 5 HISTORY
This module was forked from Damian Conway's Perl6::Gather for a few reasons. to avoid the slightly incendiary name =item to avoid the use of the Perl6::Exporter =item ~ doesn't overload to mean string context =item to no longer takes the current topic ($_) The last item is actually due to an unintended side-effect of the fact that if "take" has an array of zero length it takes $_, which is suprising at the very least. I'll fix that issue if I can. BUGS AND IRRITATIONS
It would be nice to be able to code the default case as: my @odds = gather { for (@data) { take if $_ % 2; take to_num($_) if /(?:one|three|five|nine)z/; } } or (1,3,5,7,9); but Perl 5's "or" imposes a scalar context on its left argument. This is arguably a bug and definitely an irritation. AUTHORS
o Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> o Damian Conway COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Arthur Axel "fREW" Schmidt. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.10.1 2011-02-25 Syntax::Keyword::Gather(3pm)
All times are GMT -4. The time now is 04:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy