Sponsored Content
Top Forums Shell Programming and Scripting Grabbing value from file and run command in `` Post 302886348 by sea on Thursday 30th of January 2014 09:21:33 PM
Old 01-30-2014
Using `` is 'old', use $() instead.

Your for loop copies the file you cat'ed output of 'file', defines the variable file by greping file (which you already cat'ed), and then copy file (which you cat'ed) as many times as entries are found in file (which you cat'ed) to test, overwrite 'test' as many times as entries were found.

Then you execute 3 files..
1) the file you cat'ed
2) and /tmp/[unix)$(date +y)log


Code:
for ENTRY in $(cat /some/file)
do
    workfile=$(grep -i key $ENTRY)
    cp ${workfile} test.$ENTRY
done

Assuming /some/file holds a list of diffrent files....
Now it sets the variable workfile to the content of the result of grep'ing key out of $ENTRY, and then copies the $workfile to the current path test.$ENTRY, where $ENTRY is the filename (if the (some/file contains other filenames/paths) of the file you grep'ed ALL lines containing the word 'key' in it.
At least it doesnt overwrite the file 'test' a dozen times anymore...

Can you elaborate a bit more of what you'd like to achieve?
For example with the logfiles and by the call of the 'file'?

EDIT:
Been late, of course, if test is a directory, all files are copied there.

Last edited by sea; 01-31-2014 at 01:20 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script grabbing cvs file .....

how do I write a script to checkout a file in cvs and cat the file into a file in my home directory Commands are cd /home/smr/sandbox cvsroot choose option 1 cvs co filename cat filename > /home/smr/newfilename Thank you! (4 Replies)
Discussion started by: llsmr777
4 Replies

2. Shell Programming and Scripting

Sed grabbing the last line of a file

I can grab the first line w/ sed how do you grab the last line of a file? (2 Replies)
Discussion started by: xgringo
2 Replies

3. UNIX for Dummies Questions & Answers

Grabbing result of sql command

Hi guys, Is there a way a script can run an SQL statement and dump the results into a variable which can then be used later in the script? Thanks. (3 Replies)
Discussion started by: hern14
3 Replies

4. UNIX for Dummies Questions & Answers

Grabbing a value from an output file

I am executing a stored proc and sending the results in a log file. I then want to grab one result from the output parameters (bolded below, 2) so that I can store it in a variable which will then be called in another script. There are more details that get printed in the beginning of the log file,... (3 Replies)
Discussion started by: hern14
3 Replies

5. UNIX for Dummies Questions & Answers

File Missing When Grabbing Files from SFTP Server using SCP Command

Hi, I have this problem where sometimes my files would go missing when I schedule my crontab to run the SCP command to get file from the SFTP server. My crontab will run the scripts at an interval of 3 minutes (between the two scripts) The following is the setting in my crontab. ... (1 Reply)
Discussion started by: gingervitus
1 Replies

6. Shell Programming and Scripting

Grabbing value from command output and monitoring for changes

Hi all, Very new to shell scripting so appreciate some help! There is a process count that I need to monitor, I have the AIX command that gives this value and I've cleaned it up with grep/awk so it only spits out the value I'm interested in: echo "psc -i 10050 -s RELOAD_SERVICE" | tmadmin... (14 Replies)
Discussion started by: monty77
14 Replies

7. Shell Programming and Scripting

Kornshell grabbing value from file

I have a script right now that I run a command which outputs just one word to a file. Well I need to grab that value and use it in another line of code so... touch oraclesid.txt echo $ORACLE_SID > oraclesid.txt #grab that value sqlplus v500/v500@<value> how do I grab that value from the... (6 Replies)
Discussion started by: Blogger11
6 Replies

8. Shell Programming and Scripting

Inquiry on Grabbing info from file.

Here is another script I am trying to customize currently, this script is used to send me disk space information, but at the moment I have to enter all the servers in manually SERVER= "xxx bbb ccc" ect.. how can I script it so that the servers are called off a txt file versus me entering all... (1 Reply)
Discussion started by: NelsonC
1 Replies

9. Shell Programming and Scripting

Grabbing a chunk of text from a file

Hi, I have a Report.txt file. Say the contents of this file are : 1 2 3 4 5 7 df v g gf e r dfkf lsdk dslsdklsdk Report Start: xxxxxxdad asdffsdfsdfsdfasfasdffasdf sadfasdfsadffsfsdf Report End. sdfasdfasdf sdfasfdasdfasdfasdfasdf sadfasdfsdf I need to grab from Report Start... (3 Replies)
Discussion started by: mrskittles99
3 Replies

10. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies
xpacode(7)							SAORD Documentation							xpacode(7)

NAME
XPACode - Where to Find Example/Test Code SYNOPSIS
The XPA source code directory contains two test programs, stest.c, and ctest.c that can serve as examples for writing XPA servers and clients, respectively. They also can be used to test various features of XPA. DESCRIPTION
To build the XPA test programs, execute: make All in the XPA source directory to generate the stest and ctest programs. (NB: this should work on all platforms, although we have had prob- lems with unresolved externals on one Sun/Solaris machine, for reasons still unknown.) The stest program can be executed with no arguments to start an XPA server that contains the access points: xpa, xpa1, c_xpa (containing sub-commands cmd1 and cmd2), and i_xpa. You then can use xpaset and xpaget to interact with these access points: cat xpa.c | xpaset xpa # send to xpa cat xpa.c | xpaset "xpa*" # send to xpa and xpa1 xpaget xpa # receive from xpa xpaget xpa* # receive from xpa and xpa1 etc. You also can use ctest to do the same thing, or to iterate: ctest -s -l 100 xpa # send to xpa 100 times ctest -s -l 100 "xpa*" # send to xpa and xpa1 100 times ctest -g -l 100 xpa # receive from xpa 100 times ctest -g -l 100 "xpa*" # receive from xpa and xpa1 100 times More options are available: see the stest.c and ctest.c code itself, which were used extensively to debug XPA. The file test.tcl in the XPA source directory gives examples for using the XPATclInterface. SEE ALSO
See xpa(7) for a list of XPA help pages version 2.1.14 June 7, 2012 xpacode(7)
All times are GMT -4. The time now is 06:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy