I have a file with multiple lines following this format:
The goal is to replace the title (not modifying the href) so the new lines looks like this:
The number of underscores in the "aaa_bbb_ccc" part is unknown, and that's where I'm stuck.
So far I've managed to get this result:
using this regexp:
Though one-liners are always welcome , the solution may contain multiple commands; but no matter how I try, I can't wrap my head around is how to replace the underscores with spaces, without also replacing the underscores in the href-part of the link. Is it even possible (with regexp)?
Can sed/vim execute a substitution in only part of the line (i.e. between '>' and '<'), or can I somehow run a 's/_/ /g' on the backreference '\1' before it is substituted?
There doesn't seem to be that many places where you can find information about advanced regexp substitutions (most places focus on the matching, not the replacing).
So if anyone could shed some light on this, it would be greatly appreciated.
I know I might end up using Perl or some other scripting language; but for now, I'm determined to find a solution using regexp (without scripting).
Surely it has to be possible?
(I know, I'm stubborn, but I want to learn what is possible, and not always stay with what I know works.)
Trying to find and replace one string with another string in a file
#!/usr/bin/perl
$csd_table_path = "/file.ntab";
$find_str = '--bundle_type=021';
$repl_str = '--bundle_type=021 --target=/dev/disk1s2';
if( system("/usr/bin/perl -p -i -e 's/$find_str/$repl_str/' $csd_table_path")... (2 Replies)
Hi everyone, I would really appreciate any help I could get on the following topic.
I am not very familiar with reg expressions nor with sed, I just know the basic uses. What I am trying to do is the following: I have a huge text file where I would like to replace all occurnces of a certain... (13 Replies)
hello,
I want to replace awk with a perl one liner in unix.
i use in awk REGEX and FS ( field separator) because
awk syntaxes in different unix os versions have not the same behaviour.
Awk, Nawk and GNU Awk Cheat Sheet - good coders code, great reuse
i have a file named "file" and want... (5 Replies)
Hi!
I have a difficult problem, to step up a unknown version number in a text file, and save the file. It would be great to run script.sh and the version gets increased.
Example the content of the textfile.txt
hello
version = x
bye
This include three steps
1. First find the char after... (2 Replies)
Dear all
i have the code which print 1 line of context before and after regexp, with line number
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
the code work well but any one can tell me what each letter mean {=;x;1!p;g;$!N;p;D;}
also how i can print 2 line before and onle line after ... (2 Replies)
Hi,
I am not that good with reg exp and sed. But I was just looking at something the other day and came across a situation.
When I ran the below command:
echo "123 word" | sed 's/*/(&)/'
the op was:
(123) word
But when I ran:
echo "123 word" | sed 's/*/(&)/g'
the o/p was:
(123)... (4 Replies)
exmaple, i need to replace the number "5" from all lines below with "X"?
What is the useful vim command that i can apply for..
ddpadsgg506xghssuyj
ddpadsgag546xghssuys
ddsadsgaag596xghssuy_te
ddsadsgag506xghssuy_pe
ddsadsgagc526xghssuys
ddsads506ighssuys
ddsadsgag506pghssuyk (1 Reply)
I have lines in a file like this (140,000+ entries):
value1,
value2,
value3,
"
"
I want to concatenate the three (there are 22) lines with commas so it looks like this
value1, value2, value3
"
"
I'm trying with
:g/,$/s/,$/, /g
but that is not flying.
any ideas? (6 Replies)
Hey guys, I have a file that I've slowly been awking, seding, and greping for data entry. I am down to pull the addresses out to insert them into an excel file. Each address is a few lines, but i want to put a semicolon delimiter in between each address so I can export the text file into excel and... (6 Replies)
please help:
I want to add 1 space between string and numbers:
input file:
abcd12345
output file:
abcd 1234
The following sed command does not work:
sed 's/\(+\)\(+\)/\1 \2/' file
Any ideas, please
Andy (2 Replies)