import string from file A to become variable in file B


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting import string from file A to become variable in file B
# 1  
Old 01-24-2011
import string from file A to become variable in file B

i need to fetch string from file A into varible at file B
example:
Code:
$cat A.txt
2271

B.sh
Code:
#!/bin/sh
number=2271(from file A)
kill -9 $number

so,how can i make it happen?
Thx

Last edited by Franklin52; 01-24-2011 at 03:43 AM.. Reason: Please use code tags
# 2  
Old 01-24-2011
Try like this,

Code:
kill -9 $(cat A.txt)

# 3  
Old 01-24-2011
@pravin27: I can imagine that with such a command a user would like to check a couple of things first rather than perform a kill -9 with whatever is the content of file A.txt, no?

The usual way of doing this is using a
Code:
while read var1 var2...
do
  check stuff...
  do stuff...
done < A.txt

This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 01-24-2011
Quote:
Originally Posted by bremboz
i need to fetch string from file A into varible at file B
Code:
#!/bin/sh

number=$(< fileA)

# 5  
Old 01-24-2011
Could this help ?


Code:
#!/bin/sh
while read number
do
if [ -z $(echo $number | tr -d "[0-9]") ]
then
kill -9 $number
else
echo "FAIL:PID contain non-numeric chatacter"
fi
done < A.txt


Last edited by pravin27; 01-24-2011 at 03:58 AM..
# 6  
Old 01-24-2011
Quote:
Originally Posted by Franklin52
Code:
#!/bin/sh

number=$(< fileA)

The POSIX alternative is
Code:
number=$(cat fileA)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace a string with a variable in a file using sed?

I have a file having some text like: PATH_ABC=/user/myLocation I have to replace "/user/myLocation" with a session variable say, $REPLACE_PATH, where $REPLACE_PATH=/user/myReplaceLocation The following sed command is not working. It is writing PATH_ABC=$REPLACE_PATH in the file ... (2 Replies)
Discussion started by: SKhan
2 Replies

2. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

3. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

4. Shell Programming and Scripting

Replace string in file with a variable value

Hi Fellows, I am new to shell, please help we me out in this.. i have file which some lines like this.. $$param1='12-jan-2011' $$param2='14-jan-2011' $$param3='30-jan-2011' . . .....so on.. I want to change $$param3 to '31-dec-2011'. i have variable which is storing(30-jan-2011 this... (1 Reply)
Discussion started by: victor369
1 Replies

5. Shell Programming and Scripting

Get variable string in a file

Hi all, I'm trying to get 6 variable characters before a set of 4 fixed charaters in a text file and send it in a variable. Ex: Output log file 123456.txt is full creating new log. What I want from this file is to get the 123456.txt into my variable. How do I grep this from the file when... (7 Replies)
Discussion started by: Milthiade
7 Replies

6. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

7. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

8. Shell Programming and Scripting

read string from file into variable

Hello, I need to read from a file consisting of only one integer and enter that number into variable.can anyone help? the script is written in cshell. thanks. (4 Replies)
Discussion started by: offerbukra
4 Replies

9. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

10. Shell Programming and Scripting

Replace string in a file w/ a variable value

I am trying to replace the default home page for several mac user accounts, I wrote a script that will hunt the files down and replace them with a pre-configured set. The problem I am having is that the download destination path for the browser is hard coded into a .plist (text config file) file... (5 Replies)
Discussion started by: tret
5 Replies
Login or Register to Ask a Question