|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
UNIX Shell scripting
Hi,
How to read .lst file line by line and while reading time it needs to copy the file into another file in unix shell script. could you please help in this issue. Thanks, Rami Reddy. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Welcome to the Forum.
Please post sample input and expected output. |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Hi, This is sample script. Code:
#!/bin/bash
#SCRIPT: method2.sh
#PURPOSE: Process a file line by line with redirected while-read loop.
FILENAME=test.txt
count=0
while read LINE
do
let count++
var=$LINE
cp $Line C:\Users\25267\Desktop\ram\
echo "$var"
cp $var C:\\Users\\25267\\Desktop\\ram\\
done < $FILENAME
echo -e "\nTotal $count Lines read"Thanks, Rami Reddy
Last edited by zaxxon; 02-15-2013 at 07:09 AM.. Reason: code tags, see PM |
|
#4
|
|||
|
|||
|
still not sure what exactly you need.!!! where does $Line in your script comes from? Assuming that the file content is a file name, something like this should be enough. I assume that destination folder is : /tmp Code:
for file_name in `cat test.txt` do cp $file /tmp done |
| The Following User Says Thank You to panyam For This Useful Post: | ||
Rami Reddy (02-15-2013) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Your sample script is wrong on so many points i don't even know where to start: Code:
#!/bin/bash
#SCRIPT: method2.sh
#PURPOSE: Process a file line by line with redirected while-read loop.
FILENAME=test.txt
count=0
while read LINE
do
let count++
var=$LINE
cp $Line C:\Users\25267\Desktop\ram\
echo "$var"
cp $var C:\\Users\\25267\\Desktop\\ram\\
done < $FILENAME
echo -e "\nTotal $count Lines read"1) Code:
let count++ This might have been fashionable in the seventies, todays shell all have integer arithmetic built-in and therefore: Code:
(( count++ )) 2) Code:
var=$LINE Letting aside that i fail to see the gain in copying "$LINE" to "$var" in your script (you could use $LINE directly, no), this line will only work correctly if "$LINE" contains no whitespace. Try the following and notice the error: Code:
x="abc def" y=$x echo $y correct is to quote such a statement: Code:
var="$LINE" 3) Code:
cp $Line C:\Users\25267\Desktop\ram\ First, "$Line" is nowhere defined in your script. Note that "$Line" and "$LINE" are two different variables because UNIX IS CASE SENSITIVE! Second: It seems you are trying to pass a path as argument to "cp", but this is a DOS-path (or maybe a Windows-path), but not a UNIX-path. The backslash "\" is used to declare that the next character is to be taken literally and none of its special functions should be used. For instance, you could do: Code:
cp file\* /some/where and now "*" would be taken literally. That is, not all files starting with "file" will be copied but the one file named "file*". So the file/path you are trying to copy to is named: C:Users25267Desktopram^J because you escaped with the last backslash the line feed, which probably followed the command. (The "^J" is the display value of a line feed.) While this is a valied file name for UNIX it is perhaps not what you had in mind. 4) Code:
cp $var C:\\Users\\25267\\Desktop\\ram\\ This is the same as in 2) (the quoting is missing) and more of the problems i explained in 3). This time, though, you used the backslashes to escape other backslashes and after the shell is done with your code it really looks like a DOS-path. This is still not understandable to UNIX. 5) Your script sets no exit explicit value. While this is legal it is bad practice and you should not even start to work this way. I hope this helps. bakunin |
| The Following 2 Users Say Thank You to bakunin For This Useful Post: | ||
Rami Reddy (02-15-2013), sadikkilic (02-15-2013) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| UNIX shell scripting | lokita jain | Shell Programming and Scripting | 1 | 12-05-2012 05:42 AM |
| Unix Shell Scripting | dw15 | UNIX for Dummies Questions & Answers | 3 | 08-14-2012 05:11 PM |
| Unix Shell Scripting( Calling from Unix to PLSQL) | faizsaadq | UNIX for Dummies Questions & Answers | 1 | 07-23-2012 11:41 AM |
| Need your Help on Unix Shell Scripting......... | vinayraj | UNIX for Advanced & Expert Users | 5 | 02-08-2008 06:00 AM |
| difference between AIX shell scripting and Unix shell scripting. | haroonec | Shell Programming and Scripting | 2 | 04-12-2006 08:12 AM |
|
|