How to change a substitution value in a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to change a substitution value in a file?
# 1  
Old 05-15-2010
How to change a substitution value in a file?

Hi, i want to change a subs. value in a file, with using a script..

this is my script... (example)

Code:
#!/bin/bash

NDIR=`zenity --file-selection --directory`

mv  $HOME/Desktop/myfile  /tmp/myfile.temp

XT='"'

perl -pe "s/.*/DIR=$XT`echo -e "$NDIR"`$XT/ if $. == 40"  < /tmp/myfile.temp > /tmp/myfile


mv /tmp/myfile  $HOME/Desktop

This script will change line 40 in 'myfile' file when i run it.

This is the origin value (line 40)

Code:
DIR="/home/user/Documents"

alternative solutions is welcome


Sorry, maybe this topic exists in forum but i couldn't find..

Tx..
# 2  
Old 05-15-2010
MySQL

Code:
DIR="/home/user/Documents"
NDIR="/newpath/newwpath"
fortiethline=$( (sed = file | sed -e '{N;}' -e 's/\n//' | sed -n '/^40/ {p;q}' | sed 's/^[0-9]*//') )

[ "$fortiethline" == "$DIR" ] && sed -i "40c$NDIR" file || echo "40 line is not equal $DIR"

# 3  
Old 05-15-2010
@ygemici, thanks for your help..

i used only this command for my script.

Code:
sed -i "40c$NDIR" file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Extension Substitution

Hi, I have a script in which the file name is always known, but the extension could vary. I want to be able to use a single variable; no if-else statements. For example, if I have config.txt in the directory then that's what I want to use, but if config.xml is in the directory then use that. The... (9 Replies)
Discussion started by: ocbit
9 Replies

2. Shell Programming and Scripting

Multiple variable substitution in a file in one go

I have a huge script which is defining variables with full path of commands in the beginning of code and using those variables in the script. For Example: ECHO=/bin/echo LS=/bin/ls SED=/bin/sed AWK=/bin/awk UNAME=/bin/uname PS=/bin/ps DATE=/bin/date GREP=/bin/grep $ECHO "hello... (1 Reply)
Discussion started by: veeresh_15
1 Replies

3. Shell Programming and Scripting

Awk:substitution of characters between two file elements

Hi, I have file1 like this: a 64 b 66 c 67and file2 like this: @1234 1123 aabbcc @5453 5543 ccbaI want to replace each letter of the third line in file2 with corresponding number in file1. So desired output is, @1234 1123 646466666767 @5453 5543 67676664I tried something like... (4 Replies)
Discussion started by: polsum
4 Replies

4. Shell Programming and Scripting

sed substitution or awk, need to direct change the file

I want change the file when the line contains $(AA) but NOT contains $(BB), then change $(AA) to $(AA) $(BB) eg: $(AA) something $(AA) $(BB) something (7 Replies)
Discussion started by: yanglei_fage
7 Replies

5. Shell Programming and Scripting

cat file with variable substitution

MyFile contains: ALTER TABLE $DBN.$TBN ADD $COL $TYP COMPRESS ($VAL); I need to cat the file and have it substitute all of the variables with their contents. cat MyFile does not work. The following works for the first line, but errors on the second line because of the paren: $ while read... (2 Replies)
Discussion started by: Phil27577
2 Replies

6. Shell Programming and Scripting

ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
Discussion started by: right_coaster
3 Replies

7. Solaris

Shell variables substitution in a file

Hi, I have to read a file and translate the contents including substituting the variables if any and write to another file without using sed or awk. For ex:- inputfile.txt ----------- servername=$SERVER application=$APPL outputfile.txt ------------ servername=actual server name... (2 Replies)
Discussion started by: axes
2 Replies

8. Shell Programming and Scripting

encrytion/substitution issue in a file

1) ABC::2197.12:2197.12:120217144365::+DEF:INT:1:N::::6:550.00:0.00:2009-04-29:CN:4547425069636596::6:N:mrs charles:N:PH:00010031:0001' OUTPUT - ABC::2197.12:2197.12:120217144365::+DEF:INT:1:N::::6:550.00:0.00:2009-04-29:CN:4547******636596::6:N:mrs charles:N:PH:00010031:0001' The... (5 Replies)
Discussion started by: mad_man12
5 Replies

9. Solaris

column wise substitution in a file

Hi, I have two files. Want to make an addition of the fifth column of from both the files and redirect it to a third file. Both files have same records except fifth field and same record should be inserted into new file having fifth field as addition of fifth fields of both files. for... (2 Replies)
Discussion started by: sanjay1979
2 Replies

10. Shell Programming and Scripting

Need help with file substitution

hello all just trying to write a script that will read a file (line by line) and substitute (tht line) in a different file if (tht line) is present in second file Ex: script has to read file A (line by line) and if file B has tht line it should get substituted with the line in file A ... (3 Replies)
Discussion started by: coolkid
3 Replies
Login or Register to Ask a Question