[Solved] Replacing space with hyphen in a pattern.
I have a huge text file, about 52 GB. In the file, there are patterns like these:
One can see that there is text within patterns such as [] and [[]], and I am only interested in [[]]. There is text before and after all these patterns too, for example,
.
My aim is to replace space with a hyphen for words enclosed within the pattern [[]], for example, the expected out that I am aiming for is:
I have written a C program (which I paste below) to solve this problem, but there seems to be two issues with it, one it is not perfect to place hyphen and second it seems to crash when a non-ASCII character is encountered. I was wondering whether there is a way to solve the same problem using sed or awk or something similar in BASH. The reason why I want to move to a regular expression parser in BASH is that if I spend a lot of time editing and perfecting this code, it might still crash when encountering non-ASCII characters as I found it difficult to get rid of all non-ASCII characters from the file.
Last edited by shoaibjameel123; 08-26-2016 at 11:53 AM..
Reason: Issue solved
Thanks, and sorry for not being very clear in my initial post. The output that I am trying to get is:
Another example,
Some noisy text:
Therefore, I only aim to replace space with a '-' within this pattern "[[ ]]" and no where else in the text file. The outputs that I get from the above two suggested solutions are putting hyphens everywhere.
hi,
I'm trying to calculate IP addresses and their respective calls to our apache Server. The standard format of the input is
HOST IP DATE/TIME - - "GET/POST reuest" "User Agent"
HOST IP DATE/TIME - - "GET/POST reuest" "User Agent"
HOST IP DATE/TIME - - "GET/POST reuest" "User Agent"
HOST... (2 Replies)
I'm attempting to replace a substring that contains a hyphen and not having much success, can anyone point out where i'm going wrong or suggest an alternative.
# echo /var/lib/libvirt/images/vm888b-clone.qcow | sed -e 's|vm888-clone|qaz|g'
/var/lib/libvirt/images/vm888b-clone.qcow (1 Reply)
i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of
value abc and ccc in the place of them.
Input File:
go to &abc=ddd;
if... (16 Replies)
Hi All
I am having pipe seperated inputs like
Adam|PeteR|Josh|PEter
Nick|Rave|Simon|Paul
Steve|smith|PETER|Josh
Andrew|Daniel|StAlin|peter
Rick|PETer|ADam|RAVE
i want to repleace all the occurrence of peter (in any case pattern PeteR,PEter,PETER,peter,PETer) with Peter so that output... (5 Replies)
If the string is of the pattern XxxXyzAbc...
The expected out put from sed has to be Xxx Xyz Abc ...
eg: if the string is QcfEfQfs, then the expected output is Qcf Ef Efs.
If i try to substitute the pattern with space then the sed will replace the character or pattern with space,... (1 Reply)
I have a string and want to replace the / with a space.
For example having "SP/FS/RP" I want to get "SP FS RP"
However I am having problems using gsub
set phases = `echo $Aphases | awk '{gsub(///," ")}; {print}'` (5 Replies)
I'm trying to replace a string "99999999'" with the blank where ever is there in the file. Could you please help in unix scripting.
Thank You. (6 Replies)
I would like to replace the value of * (which might have one or more whitespace(s) before and after *) using sed command in aix.
Eg: Var='Hi I am there *
Desired output: Hi I am there* (1 Reply)
Hello All,
I have a file with thousands of records:
eg:
|000222|123456987|||||||AARONSON| JOHN P|||PRIMARY |P
|000111|567894521|||||||ATHENS| WILLIAM k|||AAAA|L
Expected:
|000222|123456987|||||||AARONSON| JOHN |P|||PRIMARY |P
|000111|567894521|||||||ATHENS| WILLIAM |k|||AAAA|L
I... (6 Replies)
Hi,
I have a file with a URL text written in it within double quotes e.g.
"http://abcd.xyz.com/mno/somefile.dtd"
I want the above text to get replaced by a single space character.
I tried
cat File1.txt | sed -e 's/("http)*(dtd")/ /g' > File2.txt
But it didnt work out. Can someone... (5 Replies)