error in running the script
Hi,
I have written a script which scans two files and it replaces a field in the second file with the field present in first file if the same record is present in both the file. Following is the script cat first | while read line do usr1=`cut -d ":" -f1 line` pass1=`cut -d ":" -f2 line` cat sec | while read line1 do usr2=`cut -d ":" -f1 line1` pass2=`cut -d ":" -f2 line1` if [ $usr1 = $usr2 ] then sed -e s/$pass2/$pass1/ line1 break fi done done But when I execute this script it gives me below error $ sh scan.sh cut: Cannot open line. cut: Cannot open line. cut: Cannot open line1. cut: Cannot open line1. cut: Cannot open line1. cut: Cannot open line. cut: Cannot open line. cut: Cannot open line1. cut: Cannot open line1. cut: Cannot open line1. cut: Cannot open line. cut: Cannot open line. cut: Cannot open line1. cut: Cannot open line1. cut: Cannot open line1. $ can anyone help me on this? |
Cut looks for a filename to read from (or accepts a stream from a pipe). In your case, you are attempting to read data from a variable. Cut is looking for a file named "line" and finds none.
Also, I think you are using the read command incorrectly. I tried this: cat filename | read line #this executed with no errors echo $line #the variable was empty I don't know what the first line did, but it clearly did not put data into the variable "line". I think "read" is used to take data from the terminal (or more correctly, standard input) |
This seems like a homework problem, but I'll give you a clue anyway.
The error message "cut: Cannot open line1." implies that the program cut is trying to open a file called line1, which I don't believe is what you want. If you do this at the command line: Code:
man cut bhandu, you have on occasion posted scripts here. They will be more readable (more accurately) if you click on the [B]Go Advanced[B] button at the bottom of the editing window, enter your question (including the script), highlight the script by dragging your mouse, and then clicking on the # button at the top of the editing window. |
Quote:
Bhandu; What Scripting books have you read? There are some good free ones at tldp.org |
I couldn't help thinking about this, maybe I like homework! You could have a look at this,
Code:
#!/bin/bash Code:
#!/bin/bash |
All times are GMT -5. The time now is 05:04 PM. |