vi substitution question (or sed)
I was wondering if you could tell me the vi substitution command to insert a tab and a minus sign (-) between the "N" in QUEENSTOWN and the 19.80. This is a line in a text file. There is already a tab between the date and "VODAFONE"
I will have hundreds of similar entries, that I would like the substitution command to work for. The dollar amount could be xxx.xx and xxxx.xx. I am trying to format the text file with tab delimiters before inserting it into a mysql database. Thank you in advance! Code:
03-08-2016 <tab> VODAFONE RENTAL QUEENSTOWN 19.80 Code:
03-08-2016 <tab> VODAFONE RENTAL QUEENSTOWN <tab> -19.80 |
Seems a pretty straight-forward requirement.
People may be more inclined to help if you show us your attempts, and why you think they didn't do as you wished. |
Code:
awk '{ $(NF)="\t -"$(NF); print }' ./file.txt |
sed 's/pattern/replacement/' is the usual syntax and you can find a lot of online regexp testers (http://www.regexpal.com/)
|
@Bubushi, that assumes every line needs modifying. I assumed only a subset did - not enough info from the OP.
|
@syg00, I asumed he was trying to add tab and minus in front of last argument, otherwise it is straight forward replacing text on vi
Code:
:%s/patern/replacement/ Code:
:%s/old-text/new-text/g |
Bubushi, your first suggestion worked perfectly. Thank you! Sorry for not providing more background. I would like the command to execute hundreds of lines of the same file. Basically I am starting with the following format:
Code:
03-03 SQUARE THERAPEUTICS PORT OCONNOR TX 1988.88 Code:
:%s/\ /-2016\t/ Quote:
Code:
awk '{ $(NF)="\t -"$(NF); print }' ./file.txt Quote:
|
In vim
Code:
%s/.*\zs /\t-/ |
Wow, that is brilliant, Keefaz! It worked! Thank you. This thread is solved.
|
All times are GMT -5. The time now is 07:27 PM. |