Replace first column in 17GB File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace first column in 17GB File
# 1  
Old 12-21-2015
Replace first column in 17GB File

Hi All,

I have a 17GB file and i want to set the first column from 1234567890 to just 0, how can i do it using sed command?

thanks,

---------- Post updated at 03:09 PM ---------- Previous update was at 03:07 PM ----------

btw, my file is delimited by "|" and 1234567890 is just an example value of first column.

it's like this:

Code:
1234567890|abcddc|sfcdcd|12-12-2015|
212|fddfdgg|sdfdferruut|12-30-2014|


Last edited by Don Cragun; 12-21-2015 at 02:13 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 12-21-2015
Is it possible for you to post five to ten lines from that 17GB and an example of how the output looks like?
That would be a better request. In that way we might know what a column means to you.

---------- Post updated at 10:53 PM ---------- Previous update was at 10:41 PM ----------

Using your last example.

Code:
sed -e 's/^1234567890\\|/0\\|/' 17GB.file > Another17GB.file && mv Another17GB.file 17GB.file.

Now, as you see, there's no way around the fact that you need a minimum of 34GB of space and cpu cycles for sed to go through.
# 3  
Old 12-21-2015
No \\ and no \ because sed uses a simple RE (or BRE)! And a single -e option can be omitted.
If your sed has -i option
Code:
sed -i 's/^1234567890|/0|/' file

# 4  
Old 12-21-2015
sed -i opens a temporary file AFAIK. So be sure that $TMPDIR points to a disk that has lots of free space. IF you have enough RAM, you can direct TMPDIR to the RAM drive.
# 5  
Old 12-21-2015
Hmm, shouldn't sed -i put the temporary file near the source file, to have an efficient move(=rename)?
And the difference to Aia's explicit mv command is only that the owner/mode is preserved.
# 6  
Old 12-21-2015
Not when TMPDIR is in kernel memory (RAM). Solaris and Linux both support this.

The answer: try tracing file open calls in a sed -i command on your system against a dummied up large file, larger than the free space on the current working directory's filesystem. This is clearly contrived but will answer the question. Be sure to define TMPDIR (or whatever )

Your point is well-taken from a UNIX system developers point of view.
# 7  
Old 12-21-2015
My Solaris 10 system with TMPDIR defined elsewhere does this with gsed (Solaris version of GNU sed)

Code:
open64("somefile", O_RDONLY)                    = 3
open64("./sedz2dEGN", O_RDWR|O_CREAT|O_EXCL, 0600) = 4

Which is what I think is a major problem for large files when RAM drive is available.
Hmm.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match column 8 in file 1 with column 2 in file 2 and replace..

I am looking at the NR==FNR posts and trying to use them to achieve the following but I am not getting it. I have 2 files. I want to match column 8 in file 1 with column 2 in file 2. When they match I want to replace column 9 in file 1 with column 1 in file 2. This is and extract from file 1 ... (5 Replies)
Discussion started by: kieranfoley
5 Replies

2. Emergency UNIX and Linux Support

Need to replace a column value in UNIX file

Hi All, I am having a file like below 01098546 3 56120610010377101008311121 001382 71 003 5011339 01099413 1 42120500010247081106112121 000304 46 002 2011339 I want to replace the 78 column from 3 to 4 and I need the file as below 01098546 ... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

3. Shell Programming and Scripting

Replace column values from other file

I have one file as it has the following format File1 S No Site IP Address 1 Australia 192.168.0.1/26 2 Australia 192.168.0.2/26 3 Australia 192.168.0.3/26 I need awk/sed command to replace the column2 value ( under Site) with some other... (8 Replies)
Discussion started by: samaritan
8 Replies

4. Shell Programming and Scripting

Replace 2nd column in file

I have following entries file abc.txt abc83.out.remote TRUE abc84.out.remote TRUE abc85.out.remote TRUE abc86.out.remote TRUE Please help me, how do i toggle the entries listed in 2nd column based on the search patterns (abcxx) abcxx, i can get... (14 Replies)
Discussion started by: sdosanjh
14 Replies

5. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

6. UNIX for Dummies Questions & Answers

replace a column with values from another file

Dear all, I have a file1.pdb in pdb format and a dat file2 containing values, corresponding to the atoms in the pdb file. these values (file2.dat) need to be in the column instead of the 0.00 (file1) values for each atom in file1.pdb .(the red values must be replaced by the blue ones,in order)... (11 Replies)
Discussion started by: chen.xiao.po
11 Replies

7. Shell Programming and Scripting

Replace column with column from another file

Hello, I am trying to replace the column in file1 with the column from file2. The two files will have the same amount of rows. Each row will correspond with the same row in the other file. File1 "Replace this column" 500 13-APR-2011... (11 Replies)
Discussion started by: doobe01
11 Replies

8. UNIX for Dummies Questions & Answers

Replace values in a specified column of a file

Hello, I have a file with four columns and I would like to replace values in the second column only. An arbitrary example is: 100 A 105 B 200 B 205 C 300 C 305 D 400 D 405 E 500 E 505 F I need to replace the second column as shown below: ... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

9. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

10. UNIX for Advanced & Expert Users

how to unzip 17GB .zip file on UNIX?

I have a .zip file of size 17GB on Linux. As per my knowledge unzip(before 6.X version) doesn't work with file size greater than 4GB. I tried my best to uncompress it but didn't successed. Can anybody help me out with this? Any help will be greatly appreciated. Thank you. Regards, Chandu (2 Replies)
Discussion started by: chance04
2 Replies
Login or Register to Ask a Question