[Vi] How to put some characters on the end of a line ?
Alright, so the goal here is to use vi to do the following:
We have a list of cyclones in the world. Now i got to check whether or not the second field is more than 1000 mm. If so, than the line has to have a[*] at the end of the line. For exemple: Australia:1411:55.55:Mackay Cyclone 1918:1918:Mackay to Australia:1411:55.55:Mackay Cyclone 1918:1918:Mackay[*] I also have to use a substitute. So far i've got this but it fails, 6,$s/\([0-9]\)\1\1\1:\1/.* \[\*\] |
Why are you using vi for this? Surely something like awk is much more suitable?
Code:
awk -F: '{if ($2>1000) print $0"[*]"; else print $0}' inputfile.txt > outputfile.txt Code:
:%!awk -F: '{if ($2>1000) print $0"[*]"; else print $0}' |
/home/Local_Data
hey everyone,
is /home/Local_Data a directory located on your PC, or on a server? and how can we know that? |
the assignment tells us to use a substitution in vi. AWK is not allowed nor is the use of parameters like $0.
|
I'm afraid I don't know regular expressions well enough to help you.
|
Quote:
|
Hello Bertieboy7 and welcome to LQ,
try this one with vim: Code:
:%s/\(^\w\+:[1-9]\d\d\d:.\+\)/\1\[\*\]/ Markus Edit: %s at the beginning of the command means to do it for every line in the whole file. |
Quote:
|
All times are GMT -5. The time now is 06:42 AM. |