Replacing second line from huge files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing second line from huge files
# 1  
Old 08-11-2009
Replacing second line from huge files

I'm trying simple functionality of replacing the second line of files with some other string.
Problem is these files are huge and there are too many files to process.

Could anyone please suggest me a way to replace the second line of all files with another text in a fastest possible manner.

existing line:
<ase:aseXML xmlns:ase="urn:aseXML:r22" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:aseXML:r22 http://www.nemmco.com.au/aseXML/schemas/r22/aseXML_r22.xsd">

New line required:
<ase:aseXML xmlns:ase="urn:aseXML:r22" xmlns:xsi="/dstage/data/CISdev/MSATS/Schema/XMLSchema-instance.xml" xsi:schemaLocation="urn:aseXML:r22 /dstage/data/CISdev/MSATS/Schema/aseXML_r22.xsd">

Regards
Satish
# 2  
Old 08-11-2009
If line to replace is always in the same position in the file (ie the first two lines are always the same length), I'd use dd to do it, just dd (or head) out the first line, append the second, then dd the rest of the file on.
If thats not an option, I'd think the simplest way would be to do the following:
Code:
head -1 input.txt > output.txt
echo '<ase:aseXML xmlns:ase="urn:aseXML:r22" xmlns:xsi="/dstage/data/CISdev/MSATS/Schema/XMLSchema-instance.xml"
   xsi:schemaLocation="urn:aseXML:r22 /dstage/data/CISdev/MSATS/Schema/aseXML_r22.xsd">' >> output.txt
tail +3 input.txt >> output.txt



---------- Post updated at 05:51 PM ---------- Previous update was at 05:49 PM ----------

If the file is truly epic, you may need to stream everything, just change the head and tails to head/tail < input.txt >> output.txt (ie add the < character).
# 3  
Old 08-11-2009
Thanks.

This solution works perfect.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading ALL BUT the first and last line of a huge file

Hi. Pardon me if I'm posting a duplicate thread but.. I have a text file with over 150 Million records, file size is in the range if MB(close to GB). The requirement is to read ALL the lines excepting the FIRST LINE which is the file header and the LAST LINE which is it's trailer record. ... (8 Replies)
Discussion started by: kumarjt
8 Replies

2. UNIX for Dummies Questions & Answers

Need to replace new line characters in a huge file

Hi , I would like to replace new line characters(\n) in a huge file of about 2 million records . I tried this one (:%s/\n//g) but it's hanging there and no result. Does this command do not work if the file is big. Please let me know if you have any other options Regards Raj (1 Reply)
Discussion started by: rajeevm
1 Replies

3. Shell Programming and Scripting

Edit a Huge one line file

We have a huge file which has just one really large line; about 500 MB. I want to 1. Count all the occurrences of a phrase 2. Replace the phrase with another. Trying to open it using vi has not helped as it complains that it is too large. Can any script help? Please advise. Thank you, (12 Replies)
Discussion started by: kaushikadya
12 Replies

4. Shell Programming and Scripting

How to fix line breaks format text for huge files?

Hi, I need to correct line breaks for huge files (more than 1MM records in a file) and then format it properly. Except the header and trailer, each record starts with 'D'. Requirement:Scan the whole file except the header and trailer records and see if any of the records start with... (19 Replies)
Discussion started by: kikionline
19 Replies

5. Shell Programming and Scripting

Replacing in huge text file

I have huge text files (~120 MB)x100 which equivalents to ~11GB of data. The files contain pure numbers, actually the value of "phi" to 10 billion digits!! I know its huge!! Here are the last few lines of a file 0952899155 3233967444 3344925499 0276061529 7261968933 9683989044 3317145063... (14 Replies)
Discussion started by: shantanuthatte
14 Replies

6. Shell Programming and Scripting

Combine common line from 2 Huge files

Hi, I am having 2 huge files having line count more than 10million. The files look like: File 1 45905099 2059 942961505 3007 8450875165 7007 615565331 3015 9415586035 9012 9871573 5367 4415655 4011 44415539519 5361 3250659295 4001 5950718618 9367 File 2 44415539519 TQ03... (2 Replies)
Discussion started by: rochitsharma
2 Replies

7. Shell Programming and Scripting

Compare 2 folders to find several missing files among huge amounts of files.

Hi, all: I've got two folders, say, "folder1" and "folder2". Under each, there are thousands of files. It's quite obvious that there are some files missing in each. I just would like to find them. I believe this can be done by "diff" command. However, if I change the above question a... (1 Reply)
Discussion started by: jiapei100
1 Replies

8. Shell Programming and Scripting

Discussion line court and change context of huge data

I got a file named as data_file Contents of data_file got about IGB reads. The contents look like below: +ABC_01 AABBCCDDEEFFPPOOLLKK -ABC_01 hhhhhhhhhhhhhhhhhhhhh +ACB_100 APPPPPPPPPPIIIPPOOLLKK -ACB_100 hhhhhhhhhhHHHHHHHIhhh +AEF_55 CCCCPPPCQQFFPPOOLLKK -AEF_55 WEEGFVShhhhhhhhhhhhPP... (7 Replies)
Discussion started by: patrick87
7 Replies

9. UNIX for Dummies Questions & Answers

How to remove FIRST Line of huge text file on Solaris

i need help..!!!! i have one big text file estimate data file size 50 - 100GB with 70 Mega Rows. on OS SUN Solaris version 8 How i can remove first line of the text file. Please suggest me for solutions. Thank you very much in advance:) (5 Replies)
Discussion started by: madoatz
5 Replies

10. UNIX for Advanced & Expert Users

Insert a line as the first line into a very huge file

Hello, I need to insert a line (like a header) as the first line of a very huge file (about 3 ml rows). I am able to do it with sed, but redirecting the output and creating a new file takes quite some time. I was wondering if there was a more efficient way of doing it? Any help would be... (3 Replies)
Discussion started by: shriek
3 Replies
Login or Register to Ask a Question