Reputation: 89
I have to delete a character at nth position in a big file. Vi
hangs for such a big file. I know there will be some simple command in sed
to do so. But, I find it difficult to understand sed
scripts and its expressions.
The file I have has content like:
{"query": "Lock and", "timestamp": "2012-12-28T00:00:00.045000+00:00", "productId": 322506},,{"query": "Velvet Crush", "timestamp": "2012-12-28T00:00:00.045000+00:00", "productId": 134363}
I have to delete that extra ,
which is 130405
th character in that file. How do I use sed to achieve this.
EDIT:
Now I wish to replace all aoocurances of double comma by a single one in-place. How can that be done?
Upvotes: 1
Views: 10293
Reputation: 106
sed -i 's/.//130405' FILE
This edits the file (FILE
) in place (-i
), deleting any character (.
) at position 130405
Upvotes: 5
Reputation: 62449
Without even worrying about exactly where the double comma is, and assuming you want to fix any double comma throughout the file:
sed -e 's/,,/,/g' < file > file.new
mv file.new file
If you have a version of sed
that supports it, you can sed -i -e '...' file
to skip the redirections (but sed -i
still essentially does exactly the same thing, just with a temporary file).
Upvotes: 1