Using ARGV, acepting text from command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using ARGV, acepting text from command line
# 1  
Old 02-24-2009
Using ARGV, acepting text from command line

I want to be able to call in my file and make it do it's magic by basically giving it:

FileNAME.pl searchTerm fileToSearch

It runs, and gives me the answers I want, however, it gives me an error:
Code:
Can't open GAATTC: No such file or directory at .//restriction_map_better.pl
        line 15 (#1)
    (S inplace) The implicit opening of a file through use of the <>
    filehandle, either implicitly under the -n or -p command-line
    switches, or explicitly, failed for the indicated reason.  Usually this
    is because you don't have read permission for a file which you named on
    the command line.

This is what I have in my code, and was wondering if there was a way to bypass the error and some how just have it read from the command line the "searchTerm" without trying to use it for a search in itself, since it doesn't really exist. Or maybe if there was a way to specify the code in red so it specifically searches only the 3rd entry.

Code:
$line = "";
@sequence = "";
$int = "";
$length = 0;

$search = $ARGV[0]; # Assign with the input from command line ie THE

while ($line = <>){
        chomp($line);
        @sequence = split /\t/, $line;
        if ($sequence[1] =~ /$search/){
                $int = $`;
                $length = length($int) + 1; # +1 to give loc of found word
        }       
        print $sequence[0] . "\t" . "$length\n";
}

Thanks a bunch!
# 2  
Old 02-24-2009
The empty read function ('<>') is implicitly STDIN. If you want to read a file instead, take a look at perldoc -f open
# 3  
Old 02-24-2009
Thanks, I'll see if I can't find "perldoc -f open" and figure it out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

O argv, argv, wherefore art thou argv?

All of my machines (various open source derivatives on x86 and amd64) store argv above the stack (at a higher memory address). I am curious to learn if any systems store argv below the stack (at a lower memory address). I am particularly interested in proprietary Unices, such as Solaris, HP-UX,... (9 Replies)
Discussion started by: alister
9 Replies

2. Shell Programming and Scripting

Run a command on each line of a text file

Say I have a text file, with several lines. Each line may contain spaces or the # symbol. For each line, I want to pass that line as the path of a file, in order to add it to a tar file. I've tried this but doesn't work: cat contents.txt | xargs -0 `tar -uvf contents.tar $1`Any ideas? ... (3 Replies)
Discussion started by: Tribe
3 Replies

3. Shell Programming and Scripting

Command line: add text wrapper around words

I am trying to build a sinkhole for BIND. I created a master zone file for malicious domains and created a separate conf file, but I am stuck. I have a list of known bd domains that is updated nightly. The file simply contains the list of domains, one on each line: Bad.com Bad2.com... (4 Replies)
Discussion started by: uuallan
4 Replies

4. Shell Programming and Scripting

Replacing text in Perl given by command line

Hi I need to write a Perl script that the file given as first argument of the command line that will find all occurrences of the string given as the third argument of the command line and replace with the string given as the fourth argument. Name newfound file is specified as the second... (3 Replies)
Discussion started by: nekoj
3 Replies

5. UNIX for Advanced & Expert Users

unix command : how to insert text at the cursor location via command line?

Hi, Well my title isn't very clear I think. So to understand my goal: I have a script "test1" #!/bin/bash xvkbd -text blabla with xbindkeys, I bind F5 key in order it runs my test1 script So when I press F5, test1 runs. I'm under Emacs/Vi and I press F5 in order to have "blabla" be... (0 Replies)
Discussion started by: xib.be
0 Replies

6. Shell Programming and Scripting

cut command issue from a line of text

Hi, I got a line of text which has spaces in between and it is a long stream of characters. I want to extract the text from certain position. Below is the line and I want to take out 3 characters from 86 to 88 character position. In this line space is also a character. However when using cut... (5 Replies)
Discussion started by: asutoshch
5 Replies

7. Shell Programming and Scripting

Getting text into command line

I have an IP address in a text file and i want to use it to mount a network share. The command i will use is mount -t cifs //ipaddress/share /mnt/share -o username =hiro I just need to know how can get the IP address from the text file and into the command? Many thanks, Hiro. (10 Replies)
Discussion started by: hiro
10 Replies

8. Programming

Need help in storing command line argument argv[2] to a variable of int type

The following program takes two command line arguments. I want the second argument (fileCount) to be stored/printed as a int value. I tried my best to typecast the char to int (check the printf statement at last) but is not working...the output is some junk value. This program is in its... (3 Replies)
Discussion started by: frozensmilz
3 Replies

9. UNIX for Dummies Questions & Answers

argv command in awk

hello does anyone knows how can i reach a parameter in awk command line for example p1 f 4 p1 is an awk script. 4 is parameter i want to work with the second parameter i know it has something to do with argv command i just dont know the syntax. please help. (1 Reply)
Discussion started by: emil2006
1 Replies

10. UNIX for Dummies Questions & Answers

replace text in a file from the command line...

I am having to do a lot of searching thru files to replace words. Is there a command that i can run that will alow me to hunt thru a group of files and replace one word with another without having to open each file idividually? -thanks;) (1 Reply)
Discussion started by: dudboy
1 Replies
Login or Register to Ask a Question