Sponsored Content
Full Discussion: Issue altering end data
Top Forums Shell Programming and Scripting Issue altering end data Post 302073148 by Corona688 on Wednesday 10th of May 2006 10:46:31 AM
Old 05-10-2006
Editing a line in the middle of a file is a LOT harder than adding a line to the end of a file. Adding to the end just means opening in append mode, but selectively editing a line in the middle of it means reading in the file completely, modifying the contents, then writing back the edit and everything after it.

The reason it's so hard is, what if the length of the line changes? You can't just replace the line or stuff like this happens:
Code:
line1
line2
line3

Replace line2 with line99 and it becomes:
Code:
line1
line99line3

Because line99 is one character longer, 9 overwrites the newline character. To do this properly you have to insert more characters into the middle. Or, if the new line is shorter, delete characters from the middle. This makes it a real pain.

If you use fixed record sizes, you'll be able to just seek to and overwrite arbitrary records. See 'man dd'. bash may not be the best language for this sort of work, however.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

altering numbers in files

I want to change a number in a file into number -1.. for instance file_input is fdisdlf_s35 fdjsk_s27 fsdf_s42 jkljllljkkl_s57 ... etc now i want the output to be fdisdlf_s34 fdjsk_s26 fdsf_s41 jkljllljkkl_s56 ... etc I was think of using "sed -e 's/2/1/g' -e 's/3/2/g' -e... (4 Replies)
Discussion started by: bigboizvince
4 Replies

2. Shell Programming and Scripting

end of line issue

Hello, I am getting few text files with no EOF ( or end-of-line ) which i need to fix using a command so that i can include it in a script. Now i'm fixing this issue by opening the file in "vi" editor and adding last line. e.g., server1#wc -l temp.txt 9 temp.txt server1#cat ... (6 Replies)
Discussion started by: prvnrk
6 Replies

3. Shell Programming and Scripting

sed issue with end of line

Example, Trying to replace text to the end of a line. Text file looks like this PP= 4 PP= 412 PP= 425 I want to replace only the following line: PP= 4 with PP= 2 How can this be done with sed? (3 Replies)
Discussion started by: hanson397
3 Replies

4. Shell Programming and Scripting

Scripting question: Altering 2 field.

Hi Experts, I want to alter two filed of my data file: The _new should come to 2nd column, and _new to be removed from 4rth column, please advise, datafile.txt aa /dev/vgAA/lvol1 bb /dev/vgAA_new/lvol1 aa /dev/vgAA1/lvol2 bb /dev/vgAA1_new/lvol2 aa /dev/vgAC/lvol1 bb... (5 Replies)
Discussion started by: rveri
5 Replies

5. UNIX for Dummies Questions & Answers

Enter data at end of a file

Hi All, I have a sample datafile: 5.1 5.2 0.8 6.1 What I want to do is create an additional 3 rows with the number "0.7". so that I now have: 5.1 5.2 0.8 6.1 0.7 0.7 (3 Replies)
Discussion started by: tintin72
3 Replies

6. Shell Programming and Scripting

Appending data to the end of a line

I have searched the forms and I can not find info on appending each line of one file to the same line of another file. I know that I can cat one file to another or append the 2nd file to the end of the 1st but not quite sure how to append one line of data to another. For example File 1 has ... (2 Replies)
Discussion started by: scw132
2 Replies

7. Shell Programming and Scripting

append | to the end of each data in a file

I have a file which has data in the below format: 7810902|6783014102| || |0| |0| |0| |0|||||T|04/13/2006||9423|7421||100|2006-04-13 16:50:28|||2006-04-13 16:50:28|n|51|-1||214 1089929|||||NewSpCreateAction request successful. Activity ID = <826528>||||100|n|2006-04-13 16:50:27|2006-04-13... (3 Replies)
Discussion started by: ankianand88
3 Replies

8. Shell Programming and Scripting

Altering a variable

Can I take an argument input, lets say it's, hg0000_xy1_v2, in the script it becomes f ... then hack off the end of the filename to change the variable to hg0000 only. I tried using sed but can't figure it out. f="$f" | sed 's/_fg_v//' I could change the variable label if necessary to... (4 Replies)
Discussion started by: scribling
4 Replies

9. Programming

Altering a jar file

I have a script I am trying to test and run but it runs against a jar file. I wrote an external property file so it would redirect with my script, but it keeps going in search of the previous property file. Is there any way to externally over write the jar file and if not how do you go about... (7 Replies)
Discussion started by: risarose87
7 Replies

10. Shell Programming and Scripting

Efficiently altering and merging files in perl

I have two files fileA HEADER LINE A CommentLine A Content A .... .... .... TAILER AfileB HEADER LINE B CommentLine B Content B .... .... .... TAILER BI want to merge these two files as HEADER LINE A CommentLine A Content A (4 Replies)
Discussion started by: sam05121988
4 Replies
Ocsinventory::Agent::Common(3pm)			User Contributed Perl Documentation			  Ocsinventory::Agent::Common(3pm)

       addController()
	   Add a controller in the inventory.

       addModem()
	   Add a modem in the inventory.

       addDrive()
	   Add a partition in the inventory.

       addStorages()
	   Add a storage system (hard drive, USB key, SAN volume, etc) in the inventory.

       addMemory()
	   Add a memory module in the inventory.

       addPort()
	   Add a port module in the inventory.

       addSlot()
	   Add a slot in the inventory.

       addSoftware()
	   Register a software in the inventory.

       addMonitor()
	   Add a monitor (screen) in the inventory.

       addVideo()
	   Add a video card in the inventory.

       addSound()
	   Add a sound card in the inventory.

       addNetwork()
	   Register a network in the inventory.

       setHardware()
	   Save global information regarding the machine.

	   The use of setHardware() to update USERID and PROCESSOR* informations is deprecated, please, use addUser() and addCPU() instead.

       setBios()
	   Set BIOS informations.

       addCPU()
	   Add a CPU in the inventory.

       addUser()
	   Add an user in the list of logged user.

       addPrinter()
	   Add a printer in the inventory.

       addVirtualMachine()
	   Add a Virtual Machine in the inventory.

       addProcess()
	   Record a running process in the inventory.

       addIpDiscoverEntry()
	   IpDiscover is used to identify network interface on the local network. This is done on the ARP level.

	   This function adds a network interface in the inventory.

       setAccessLog()
	   What is that for? :)

       flushXMlTags()
	   Clear the content of $common->{xmltags} (to use after adding it in XML)

POD ERRORS
Hey! The above document had some coding errors, which are explained below: Around line 34: '=item' outside of any '=over' perl v5.14.2 2012-04-12 Ocsinventory::Agent::Common(3pm)
All times are GMT -4. The time now is 08:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy