Sponsored Content
Special Forums UNIX Desktop Questions & Answers shell overwrite lines in a file Post 302251824 by ACTGADE on Tuesday 28th of October 2008 07:47:48 AM
Old 10-28-2008
Found a SED solution which looks:

# getCounter
var="# <Path to Project>"
var1="/root/Desktop/Textdatei.txt"
Counter=`sed -n -e "/${var}/=" $var1`
FinalCounter=`expr $Counter + 1`

# lineSubstitution
varneu="/tmp/noch/watdazu/gesch/"
sed -e "${FinalCounter}c\\${varneu}" $var1 > xxx.txt # Problem: described below
cat xxx.txt > $var1 # Bad solution
rm xxx.txt

The remaining problem is that I wished to write the whole samplestorage back to the original file:

1st solution: sed -e "${FinalCounter}c\\${varneu}" $var1 > $var1
2nd solution sed -e "${FinalCounter}c\\${varneu}w $var1" $var1

in solution no. 1 the file (Textdatei.txt) is always empty. I do not understand for what reason the file will be overwritten with empty lines?

in solution no 2. I have the problem with the syntax. the w $var1 is always just added to the $varneu in the substituted line. I tried with several charcters before w like (/, \, etc. ) but I did'nt hit the right one.

Can you advice how to go along with this?

tks in advance

p.s. this is my Textdatei.txt:

#############################################
#***************Use this File **************#
#############################################
#
#

# <ProjectName>
AlterName

#
#
#
# <Path to Project>
/tmp/noch/watdazu/gesch/

#
#
#

Edit/Delete Message Reply With Quote Multi-Quote This Message Quick reply to this message
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

overwrite specific lines in a file

Hi all, I am trying to overwrite some lines of a very big file. I know the number of the line but I don't know how to point the cursor on its beginning. there is an option to notice the offset in lines? thanks! (7 Replies)
Discussion started by: csecnarf
7 Replies

2. UNIX for Dummies Questions & Answers

Restrict file overwrite through FTP

How can I restrict a user from overwriting a file once he has uploaded it through FTP. He can view the file but can't delete or overwrite it. (OS is UNIX, there is no restriction on client FTP software) Will be very glad if someone could resolve this problem. Thanks Imran Aziz Khan ... (7 Replies)
Discussion started by: imranak7
7 Replies

3. Shell Programming and Scripting

Overwrite a running shell script

Hello all, This might be a dumb question...but i am running into this situation. I have a shell script that is currently in running state. It has big sql's in it and will run for few days. What happens if I change the shell now? Eg: a.shl is running and i want to mv b.shl a.shl I... (5 Replies)
Discussion started by: gsjdrr
5 Replies

4. Shell Programming and Scripting

Unable to overwrite but can delete file

I'm debugging a ksh script written by someone else that does the following: It runs a command and redirects stdout to a file called dberror that already exists using ">". This command fails with the following error: The file access permissions do not allow the specified action. dberror:... (1 Reply)
Discussion started by: savage66
1 Replies

5. UNIX for Dummies Questions & Answers

overwrite file in multiple folders

I need to update the contents of a file that exists in several hundred folders. I'm on a mac. Can I use Terminal to execute a linux/unix command that will accomplish the overwriting of the file? (2 Replies)
Discussion started by: webguy262
2 Replies

6. Shell Programming and Scripting

Need to overwrite shell script using vi editor

I have an existing shell script that I am trying to modify. I have about 10 lines of info I want to overwrite using text someone emailed to me. I guess what I am trying to do basically is like a copy/paste, but it's not working for me. I am using Cygwin and vi editor. I open the script and... (4 Replies)
Discussion started by: kimberlyg2007
4 Replies

7. Shell Programming and Scripting

Shell script to overwrite a file

Hi Guys, My requirement as follows, i want to write a shell script to display the files of a folder, i export it to a file to mail the file. The problem is the exported file is getting appended every time I run the script. I just want the file to be over written. can anyone suggest?? ... (4 Replies)
Discussion started by: Karthick N
4 Replies

8. Shell Programming and Scripting

Overwrite file every day

Hi Friends, I have written a script to capture system performance every hour and redirected to output file. How to overwrite the file every next day? Thanks Suresh (4 Replies)
Discussion started by: suresh3566
4 Replies

9. Shell Programming and Scripting

Wget download file ( do not overwrite )

Hello all, I want to write auto update script for my embedded device, which can check and download newer version of my program and extract the files on the device. The download center is hosted on remote web server . Script checks the hosted file on web site and if the new version is there... (8 Replies)
Discussion started by: stefki
8 Replies

10. Shell Programming and Scripting

How to Undo overwrite file in UNIX?

Hi, Could anyone please advise if its possible in unix to undo the changes for a file that has been overwrriten. By mistake i have overwritten a file and now i need the original file, is there a way? Please Help!!! (2 Replies)
Discussion started by: mail.chiranjit
2 Replies
LIST(3) 								 1								   LIST(3)

list - Assign variables as if they were an array

SYNOPSIS
array list (mixed $var1, [mixed $...]) DESCRIPTION
Like array(3), this is not really a function, but a language construct. list(3) is used to assign a list of variables in one operation. PARAMETERS
o $var1 - A variable. RETURN VALUES
Returns the assigned array. EXAMPLES
Example #1 list(3) examples <?php $info = array('coffee', 'brown', 'caffeine'); // Listing all the variables list($drink, $color, $power) = $info; echo "$drink is $color and $power makes it special. "; // Listing some of them list($drink, , $power) = $info; echo "$drink has $power. "; // Or let's skip to only the third one list( , , $power) = $info; echo "I need $power! "; // list() doesn't work with strings list($bar) = "abcde"; var_dump($bar); // NULL ?> Example #2 An example use of list(3) <table> <tr> <th>Employee name</th> <th>Salary</th> </tr> <?php $result = $pdo->query("SELECT id, name, salary FROM employees"); while (list($id, $name, $salary) = $result->fetch(PDO::FETCH_NUM)) { echo " <tr> " . " <td><a href="info.php?id=$id">$name</a></td> " . " <td>$salary</td> " . " </tr> "; } ?> </table> Example #3 Using nested list(3) <?php list($a, list($b, $c)) = array(1, array(2, 3)); var_dump($a, $b, $c); ?> int(1) int(2) int(3) Example #4 Using list(3) with array indices <?php $info = array('coffee', 'brown', 'caffeine'); list($a[0], $a[1], $a[2]) = $info; var_dump($a); ?> Gives the following output (note the order of the elements compared in which order they were written in the list(3) syntax): array(3) { [2]=> string(8) "caffeine" [1]=> string(5) "brown" [0]=> string(6) "coffee" } NOTES
Warning list(3) assigns the values starting with the right-most parameter. If you are using plain variables, you don't have to worry about this. But if you are using arrays with indices you usually expect the order of the indices in the array the same you wrote in the list(3) from left to right; which it isn't. It's assigned in the reverse order. Warning Modification of the array during list(3) execution (e.g. using list($a, $b) = $b) results in undefined behavior. Note list(3) only works on numerical arrays and assumes the numerical indices start at 0. SEE ALSO
each(3), array(3), extract(3). PHP Documentation Group LIST(3)
All times are GMT -4. The time now is 07:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy