Hi,
I'm looking to perform multiple operations on a text file. At a minimum, I want to know how to replace duplicate text within a row. Below is source.txt file contents.
"117981" "YOC AG"<tab>
"118127" "118127"<tab>
"702337" "Carlson Marketing Worldwide, I"<tab>
Ideally, the output file target.txt will:
1.) Replace the single space between column one and two.
2.) Remove the trailing tab character in each row.
3.) If the second column is a duplicate of the first column, it should be replace with empty double quotes.
4.) Add a prefix text "Col1", text to each row.
"Col1","117981","YOC AG"
"Col1","118127",""
"Col1","702337","Carlson Marketing Worldwide, I"
Looking for a purely dos batch based solution for this.
Thanks!
Prefix, Replace duplicate text in a line
Moderator: DosItHelp
Re: Prefix, Replace duplicate text in a line
by AWK for Windows:
Code: Select all
>result.txt awk -F\" -v "C=," "{if ($2==$4) $4 = \"\";print FS\"Col1\"FS C FS$2FS C FS$4FS}" source.txt