Execute command on first column (filename) retrieved from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute command on first column (filename) retrieved from a file
# 8  
Old 09-13-2010
More readable is to use a loop like this:
Code:
while read file
do
  cleartool co -nc "$file"
  cp "${file##*/}" /another/dir
  mv "${file##*/}" /yet/another/dir
done < abcd.txt

# 9  
Old 09-13-2010
Quote:
Originally Posted by Franklin52
More readable is to use a loop like this:
Code:
while read file
do
  cleartool co -nc "$file"
  cp "${file##*/}" /another/dir
  mv "${file##*/}" /yet/another/dir
done < abcd.txt

Much better. I'd go with that.

But I started with xargs, and I wasn't going to let it beat me Smilie
# 10  
Old 09-13-2010
Sorry if this is stupid question!
But the code that Franklin gave, what will be the extension of the file which contains the code?
if i give a.sh then while running, it says Permission Denied. Smilie
# 11  
Old 09-13-2010
Quote:
Originally Posted by scottn
Much better. I'd go with that.

But I started with xargs, and I wasn't going to let it beat me Smilie
I know that feeling all too well Smilie

Quote:
Originally Posted by royzlife
Sorry if this is stupid question!
But the code that Franklin gave, what will be the extension of the file which contains the code?
if i give a.sh then while running, it says Permission Denied. Smilie
Make the file executable with:
Code:
chmod 755 scriptname

And run it with:
Code:
./scriptname

# 12  
Old 09-13-2010
Yes Franklin i just did that but found some more issues.
Code:
while read file
do
  cp "${file##*/}" ~/targetdir/ 
done < abcd.txt

I had run this file using
Code:
$./copy

I have already checked out the files and the target directory is empty.

Some more info about source dir structure:

Code:
$srcdir> ls
dir1/
dir2/
c.txt
.....
$srcdir>./copy
cp: cannot access a.txt


Last edited by royzlife; 09-13-2010 at 05:55 AM.. Reason: Code
# 13  
Old 09-13-2010
Sorry, the script should be something like:
Code:
while read file
do
  cleartool co -nc "$file"
  cp "$file" /another/dir/"${file##*/}"
  mv "$file" /yet/another/dir/"${file##*/}"
done < abcd.txt

This User Gave Thanks to Franklin52 For This Post:
# 14  
Old 09-15-2010
Twist!

Hi Scott / Franklin,

i want the output of the following command "cleartool diff" be stored in a file -
i used :
Code:
xargs -n1 -I{} < latest.txt ksh -c "cleartool diff -pre -ser  {} > diff.txt"

and this worked

BUT

when I am trying to modify the statement to:
Code:
xargs -n1 -I{} < latest.txt ksh -c "autotest {} > result.txt"

I am seeing only a first few lines of the output is being redirected to result.txt but the actual report is coming on the screen! Ideally I want the report displayed in the screen to come to result.txt
Note: auottest is a custommade script which taked individual file names from latest.txt and runs.

Please help!Smilie

Last edited by royzlife; 09-15-2010 at 08:41 AM.. Reason: Info
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using filename to determine a prefix that needs to be added to string column on file?

Possible filenames: CDD_Whatever.txt DDD_Whatever.txt If the file prefix = CDD, I'd like to prefix every person ID (second column in my examples below) on the file with "c-" If the file prefix = DDD, I'd like to prefix ever person ID with "d-" Input: Desired Output: Any help... (2 Replies)
Discussion started by: lrluis
2 Replies

2. Shell Programming and Scripting

Which shell script will call if i execute sh (without filename)?

Hi Friends, The below shell script is written by third party to create B2k_session_id.iam trying to execute this script.When i execute below script it is calling some other scripts.How to find which scripts is calling? . `execom commfunc.com` echo " $PRESENTATION_MODE " if then echo... (1 Reply)
Discussion started by: vadlamudy
1 Replies

3. UNIX for Dummies Questions & Answers

Add a new column to txt file containing filename

I would like help adding a new column to a large txt file (~10MB) that contains the filename. I have searched other posts but have not found an adequate solution. I need this extra column so I can concatenate >100 files and perform awk searches on this large file. My current txt file look... (4 Replies)
Discussion started by: kellywilliams
4 Replies

4. Shell Programming and Scripting

find specific file names and execute a command depending on file's name

Hi, As a newbie, I'm desperate ro make my shell script work. I'd like a script which checks all the files in a directory, check the file name, if the file name ends with "extracted", store it in a variable, if it has a suffix of ".roi" stores in another variable. I'm going to use these two... (3 Replies)
Discussion started by: armando110
3 Replies

5. Shell Programming and Scripting

KSH Script to Execute command from specific column in file

Hi Unix Experts,Team I have a file (say comand_file.prm), The file has a command specified in column 6 (say "./execute_script.sh"). I want to execute this command in my script. I am writing a KSH script to achieve this. Could you please assist me with this. (6 Replies)
Discussion started by: Jeevanm
6 Replies

6. Shell Programming and Scripting

Concatenate strings retrieved from a file and write it into another file

Hi, I have a file files.txt containing data as below: abc;xyz uvw;pqr 123;456 I want to develop strings like below using the above data and write them into another file: www/xxx/abc/yyy/xyz www/xxx/uvw/yyy/pqr www/xxx/123/yyy/456 All this needs to be done through .sh file. ... (4 Replies)
Discussion started by: archana.n
4 Replies

7. Shell Programming and Scripting

Merge CSV files and create a column with the filename from the original file

Hello everyone!! I am not completely new to shell script but I havent been able to find the answer to my problem and I'm sure there are some smart brains here up for the challenge :D. I have several CSV files that I need to combine into one, but I also need to know where each row came from.... (7 Replies)
Discussion started by: fransanchezoria
7 Replies

8. Shell Programming and Scripting

Take the value of variable from a file and execute a command for each value

Hello Experts, I would like to know the best way to assign a value to variable from a given file and execute a command including this variable for each entry from the file. to be more clear, i have a file with different lines (each line with a different value). i want to substitute the variable... (2 Replies)
Discussion started by: Dendany83
2 Replies

9. Programming

Assign a command to execute a file

Hi all, I want to assign a command name to a file.e.g. suppose I have a .sh file "xyz.sh". I want to execute the file by typing in "abc". The desired output is: $ abc should execute the "xyz.sh" file. Kind Regards, Qasim (4 Replies)
Discussion started by: qasim
4 Replies

10. HP-UX

How to execute a remote file with local command

Hello, I know this is somewhat strange, but please let me know if possible. I want to execute a program file in the remote machine with command on the local machine. Let me make things more clear. Suppose I have a cc on my local system and do not have that on the remote system. I want to use... (2 Replies)
Discussion started by: Veera_Raghav
2 Replies
Login or Register to Ask a Question