Sponsored Content
The Lounge What is on Your Mind? Speculative Shell Feature Brainstorming Post 302514403 by Corona688 on Friday 15th of April 2011 03:29:19 PM
Old 04-15-2011
Another way to handle anonymous files could be similar to the awk way. When you redirect a file in awk, it stays open, referring to the same filename later just gets you the same handle over and over.

Code:
LINE=1
# Read lines from "otherfile" and "cmpfile" one by one, without
# redirecting the entire loop's stdin.
# Also set the close-on-exec flag for files opened in this fashion.
while read LINE <<"otherfile" && read OTHERLINE <<"cmpfile"
do
        if [ "$LINE" != "$OTHERLINE" ]
        then
                echo "Line $LINE doesn't match"
                echo "What would you like to do?"

                read RESPONSE
                case "${RESPONSE}" in
                *)   # todo: something
                      ;;
                 esac
        fi
        ((LINE++))
done

close "cmpfile" "otherfile"

Using << for 'keep the file open' seems a nice opposite of the >> 'append to file' redirection. This breaks the syntax for here-documents though. Not quite sure how to get the FD out of that either, maybe $<"filename" ?

Last edited by Corona688; 04-15-2011 at 04:35 PM..
 

4 More Discussions You Might Find Interesting

1. SCO

BASH-like feature. is possible ?

Greetings... i was wondering if there is any shell configuration or third party application that enables the command history by pressing keyboard up arrow, like GNU/BASH does or are there an SCO compatible bash versio to download? where ? just wondering (sory my stinky english) (2 Replies)
Discussion started by: nEuRoMaNcEr
2 Replies

2. Shell Programming and Scripting

Creating a command history feature in a simple UNIX shell using C

I'm trying to write a history feature to a very simple UNIX shell that will list the last 10 commands used when control-c is pressed. A user can then run a previous command by typing r x, where x is the first letter of the command. I'm having quite a bit of trouble figuring out what I need to do, I... (2 Replies)
Discussion started by: -=Cn=-
2 Replies

3. UNIX for Dummies Questions & Answers

brainstorming automated response

I am managing a database of files for which there is a drop-box and multiple users. what i would like to do is set a criteria for files coming into the drop-box based on file structure. (they must be like this W*/image/W*-1234/0-999.tif) If the files do not match the criteria i want them to be... (1 Reply)
Discussion started by: Movomito
1 Replies

4. UNIX for Beginners Questions & Answers

Can we create any check-point feature in shell ?

I have a script as below and say its failed @ function fs_ck {} then it should exit and next time i execute it it should start from fs_ck {} only Please advise #!/bin/bash logging {} fs_ck {} bkp {} dply {} ## main function### echo Sstarting script echo '####' logging fs_ck... (3 Replies)
Discussion started by: abhaydas
3 Replies
Mixin::Linewise::Readers(3pm)				User Contributed Perl Documentation			     Mixin::Linewise::Readers(3pm)

NAME
Mixin::Linewise::Readers - get linewise readers for strings and filenames SYNOPSIS
package Your::Pkg; use Mixin::Linewise::Readers -readers; sub read_handle { my ($self, $handle) = @_; LINE: while (my $line = $handle->getline) { next LINE if $line =~ /^#/; print "non-comment: $line"; } } Then: use Your::Pkg; Your::Pkg->read_file($filename); Your::Pkg->read_string($string); Your::Pkg->read_handle($fh); EXPORTS
"read_file" and "read_string" are exported by default. Either can be requested individually, or renamed. They are generated by Sub::Exporter, so consult its documentation for more information. Both can be generated with the option "method" which requests that a method other than "read_handle" is called with the created IO::Handle. read_file Your::Pkg->read_file($filename); If generated, the "read_file" export attempts to open the named file for reading, and then calls "read_handle" on the opened handle. Any arguments after $filename are passed along after to "read_handle". read_string Your::Pkg->read_string($string); If generated, the "read_string" creates an IO::String handle from the given string, and then calls "read_handle" on the opened handle. Any arguments after $string are passed along after to "read_handle". BUGS
Bugs should be reported via the CPAN bug tracker at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mixin-Linewise> For other issues, or commercial enhancement or support, contact the author. AUTHOR
Ricardo SIGNES, "<rjbs@cpan.org>" COPYRIGHT
Copyright 2008, Ricardo SIGNES. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-02-14 Mixin::Linewise::Readers(3pm)
All times are GMT -4. The time now is 07:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy