![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Replacing the last data of each line ina file | jisha | Shell Programming and Scripting | 6 | 08-04-2008 04:47 AM |
| Replacing a line in a file - HELP!!! | maxmave | Shell Programming and Scripting | 1 | 06-04-2008 08:55 PM |
| replacing multiple lines with single line | siba.s.nayak | Shell Programming and Scripting | 3 | 05-27-2008 11:43 PM |
| replacing a line of unknown charecters in a file | malavm | Shell Programming and Scripting | 12 | 07-26-2007 01:25 AM |
| replacing specific lines in a file | hcclnoodles | Shell Programming and Scripting | 6 | 09-30-2006 08:35 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
replacing first line or lines in a file
hey guys, how do i replace only a line within a file without messing up the rest of the contents of the file?
see, if possible can you guys give me a straight forward way to do this. i dont want a complex command. what i mean is i know i can accomplish this by using sed, well, i think i can, but i keep circling around and dont know the exact command. what i'm trying to do is run a script remotely that checks diskspace on a server. if diskspac is above a certain percentage this script will look at the file i'm trying to edit and delete files on the disk based on the threshold, number of days, given in the file. this may be confusing but really all i need is the one liner that will just replace a line for me if the script fails to free up enough space. thanks guys. |
| Forum Sponsor | ||
|
|
|
|||
|
Since the source file and destination file are the same, consider doing something like this.
Input file called inputfile.txt contains just the word 'This' commandline perl -pi -w -e 's/This/I did it/g;' inputfile.txt #This replaces the word This with I did it all from the commandline inside script called myscript.pl perl -pi -w -e 's/This/I did it/g;' $1 #Put this perl line inside a script and run it. Passing your input file to the script Run script from commandline. #myscript.pl inputfile.txt -X |
|
|||
|
Quote:
thanks for your suggestions. what i ended up doing was just reconstructing the file using a synchronized copy of the original. what i was trying to edit couldn't be done with sed or awk. i tried but it just couldn't be done. so i just used a combination of echo, awk, tee and a variety of other commands to draw out out the wanted line and then appended the rest of the file content to the end of that file |
|||
| Google The UNIX and Linux Forums |