Replace With Text From The Line Above?
up vote
4
down vote
favorite
I have a text file like this:
ge-0/0/45.0,First-Floor-Security,13
,Voice_First_Floor,18
ge-0/0/46.0,First-Floor-Security,13
,Voice_First_Floor,18
ge-0/0/47.0,AV-Media,155
,Building-Automation,75
,CobraNet,156
,First-Floor-Management,19
,First-Floor-Pavilion,11
,First-Floor-Security,13
,First-Floor-Users,10
,Guest-Wired,3
,Video,150
,Voice_First_Floor,18
,Wireless-Corp,410
,Wireless-Guest,420
,Wireless-Mtg,400
,Wireless-Voice,430
ge-1/0/0.0,First-Floor-Users,10
,Voice_First_Floor,18
I looking for a command to grab the first field of the line above and insert it into the line below. So for example, my resulting file would look like this:
ge-0/0/45.0,First-Floor-Security,13
ge-0/0/45.0,Voice_First_Floor,18
ge-0/0/46.0,First-Floor-Security,13
ge-0/0/46.0,Voice_First_Floor,18
ge-0/0/47.0,AV-Media,155
ge-0/0/47.0,Building-Automation,75
ge-0/0/47.0,CobraNet,156
ge-0/0/47.0,First-Floor-Management,19
ge-0/0/47.0,First-Floor-Pavilion,11
ge-0/0/47.0,First-Floor-Security,13
ge-0/0/47.0,First-Floor-Users,10
ge-0/0/47.0,Guest-Wired,3
ge-0/0/47.0,Video,150
ge-0/0/47.0,Voice_First_Floor,18
ge-0/0/47.0,Wireless-Corp,410
ge-0/0/47.0,Wireless-Guest,420
ge-0/0/47.0,Wireless-Mtg,400
ge-0/0/47.0,Wireless-Voice,430
ge-1/0/0.0,First-Floor-Users,10
ge-1/0/0.0,Voice_First_Floor,18
I have some understanding about grouping and backreferences but cannot seem to find a way to search, create a backreference, and then use that backreference in a different line. Is this possible? If so, would you please point me in the right direction?
Thanks,
Drew
search replace
New contributor
add a comment |
up vote
4
down vote
favorite
I have a text file like this:
ge-0/0/45.0,First-Floor-Security,13
,Voice_First_Floor,18
ge-0/0/46.0,First-Floor-Security,13
,Voice_First_Floor,18
ge-0/0/47.0,AV-Media,155
,Building-Automation,75
,CobraNet,156
,First-Floor-Management,19
,First-Floor-Pavilion,11
,First-Floor-Security,13
,First-Floor-Users,10
,Guest-Wired,3
,Video,150
,Voice_First_Floor,18
,Wireless-Corp,410
,Wireless-Guest,420
,Wireless-Mtg,400
,Wireless-Voice,430
ge-1/0/0.0,First-Floor-Users,10
,Voice_First_Floor,18
I looking for a command to grab the first field of the line above and insert it into the line below. So for example, my resulting file would look like this:
ge-0/0/45.0,First-Floor-Security,13
ge-0/0/45.0,Voice_First_Floor,18
ge-0/0/46.0,First-Floor-Security,13
ge-0/0/46.0,Voice_First_Floor,18
ge-0/0/47.0,AV-Media,155
ge-0/0/47.0,Building-Automation,75
ge-0/0/47.0,CobraNet,156
ge-0/0/47.0,First-Floor-Management,19
ge-0/0/47.0,First-Floor-Pavilion,11
ge-0/0/47.0,First-Floor-Security,13
ge-0/0/47.0,First-Floor-Users,10
ge-0/0/47.0,Guest-Wired,3
ge-0/0/47.0,Video,150
ge-0/0/47.0,Voice_First_Floor,18
ge-0/0/47.0,Wireless-Corp,410
ge-0/0/47.0,Wireless-Guest,420
ge-0/0/47.0,Wireless-Mtg,400
ge-0/0/47.0,Wireless-Voice,430
ge-1/0/0.0,First-Floor-Users,10
ge-1/0/0.0,Voice_First_Floor,18
I have some understanding about grouping and backreferences but cannot seem to find a way to search, create a backreference, and then use that backreference in a different line. Is this possible? If so, would you please point me in the right direction?
Thanks,
Drew
search replace
New contributor
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I have a text file like this:
ge-0/0/45.0,First-Floor-Security,13
,Voice_First_Floor,18
ge-0/0/46.0,First-Floor-Security,13
,Voice_First_Floor,18
ge-0/0/47.0,AV-Media,155
,Building-Automation,75
,CobraNet,156
,First-Floor-Management,19
,First-Floor-Pavilion,11
,First-Floor-Security,13
,First-Floor-Users,10
,Guest-Wired,3
,Video,150
,Voice_First_Floor,18
,Wireless-Corp,410
,Wireless-Guest,420
,Wireless-Mtg,400
,Wireless-Voice,430
ge-1/0/0.0,First-Floor-Users,10
,Voice_First_Floor,18
I looking for a command to grab the first field of the line above and insert it into the line below. So for example, my resulting file would look like this:
ge-0/0/45.0,First-Floor-Security,13
ge-0/0/45.0,Voice_First_Floor,18
ge-0/0/46.0,First-Floor-Security,13
ge-0/0/46.0,Voice_First_Floor,18
ge-0/0/47.0,AV-Media,155
ge-0/0/47.0,Building-Automation,75
ge-0/0/47.0,CobraNet,156
ge-0/0/47.0,First-Floor-Management,19
ge-0/0/47.0,First-Floor-Pavilion,11
ge-0/0/47.0,First-Floor-Security,13
ge-0/0/47.0,First-Floor-Users,10
ge-0/0/47.0,Guest-Wired,3
ge-0/0/47.0,Video,150
ge-0/0/47.0,Voice_First_Floor,18
ge-0/0/47.0,Wireless-Corp,410
ge-0/0/47.0,Wireless-Guest,420
ge-0/0/47.0,Wireless-Mtg,400
ge-0/0/47.0,Wireless-Voice,430
ge-1/0/0.0,First-Floor-Users,10
ge-1/0/0.0,Voice_First_Floor,18
I have some understanding about grouping and backreferences but cannot seem to find a way to search, create a backreference, and then use that backreference in a different line. Is this possible? If so, would you please point me in the right direction?
Thanks,
Drew
search replace
New contributor
I have a text file like this:
ge-0/0/45.0,First-Floor-Security,13
,Voice_First_Floor,18
ge-0/0/46.0,First-Floor-Security,13
,Voice_First_Floor,18
ge-0/0/47.0,AV-Media,155
,Building-Automation,75
,CobraNet,156
,First-Floor-Management,19
,First-Floor-Pavilion,11
,First-Floor-Security,13
,First-Floor-Users,10
,Guest-Wired,3
,Video,150
,Voice_First_Floor,18
,Wireless-Corp,410
,Wireless-Guest,420
,Wireless-Mtg,400
,Wireless-Voice,430
ge-1/0/0.0,First-Floor-Users,10
,Voice_First_Floor,18
I looking for a command to grab the first field of the line above and insert it into the line below. So for example, my resulting file would look like this:
ge-0/0/45.0,First-Floor-Security,13
ge-0/0/45.0,Voice_First_Floor,18
ge-0/0/46.0,First-Floor-Security,13
ge-0/0/46.0,Voice_First_Floor,18
ge-0/0/47.0,AV-Media,155
ge-0/0/47.0,Building-Automation,75
ge-0/0/47.0,CobraNet,156
ge-0/0/47.0,First-Floor-Management,19
ge-0/0/47.0,First-Floor-Pavilion,11
ge-0/0/47.0,First-Floor-Security,13
ge-0/0/47.0,First-Floor-Users,10
ge-0/0/47.0,Guest-Wired,3
ge-0/0/47.0,Video,150
ge-0/0/47.0,Voice_First_Floor,18
ge-0/0/47.0,Wireless-Corp,410
ge-0/0/47.0,Wireless-Guest,420
ge-0/0/47.0,Wireless-Mtg,400
ge-0/0/47.0,Wireless-Voice,430
ge-1/0/0.0,First-Floor-Users,10
ge-1/0/0.0,Voice_First_Floor,18
I have some understanding about grouping and backreferences but cannot seem to find a way to search, create a backreference, and then use that backreference in a different line. Is this possible? If so, would you please point me in the right direction?
Thanks,
Drew
search replace
search replace
New contributor
New contributor
New contributor
asked Nov 16 at 20:32
610Drew
211
211
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
4
down vote
Here's a command you could use:
:g/^,/norm 0kyt,jP
This uses the "global" command. Here's what it basically does:
:g/<regex>/<command>
will run "command" on every single line that matches the "regex". Our regex is pretty simple: Any line that starts with (^
) a comma (,
).
The command:
norm 0kyt,jP
norm
means "run these characters like I typed them in normal mode". So 0k
goes to the beginning of the last line with a comma. yt,
is yank until ,
. jP
goes back to the line we matched on and pastes from the clipboard before the comma.
Conveniently, this runs each line in order, so it works on multiple entryless lines in a row, such as
,Building-Automation,75
,CobraNet,156
,First-Floor-Management,19
,First-Floor-Pavilion,11
,First-Floor-Security,13
,First-Floor-Users,10
,Guest-Wired,3
,Video,150
,Voice_First_Floor,18
,Wireless-Corp,410
,Wireless-Guest,420
,Wireless-Mtg,400
,Wireless-Voice,430
This is because on the "building automation" line, it will grab the "ge-0/0/47.0" from the previous line, and then paste it on this line. Then, on the "cobraNet" line, it will grab the new "ge-0/0/47.0" from the "building automation" line, etc.
1
That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
– 610Drew
Nov 16 at 21:02
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
Here's a command you could use:
:g/^,/norm 0kyt,jP
This uses the "global" command. Here's what it basically does:
:g/<regex>/<command>
will run "command" on every single line that matches the "regex". Our regex is pretty simple: Any line that starts with (^
) a comma (,
).
The command:
norm 0kyt,jP
norm
means "run these characters like I typed them in normal mode". So 0k
goes to the beginning of the last line with a comma. yt,
is yank until ,
. jP
goes back to the line we matched on and pastes from the clipboard before the comma.
Conveniently, this runs each line in order, so it works on multiple entryless lines in a row, such as
,Building-Automation,75
,CobraNet,156
,First-Floor-Management,19
,First-Floor-Pavilion,11
,First-Floor-Security,13
,First-Floor-Users,10
,Guest-Wired,3
,Video,150
,Voice_First_Floor,18
,Wireless-Corp,410
,Wireless-Guest,420
,Wireless-Mtg,400
,Wireless-Voice,430
This is because on the "building automation" line, it will grab the "ge-0/0/47.0" from the previous line, and then paste it on this line. Then, on the "cobraNet" line, it will grab the new "ge-0/0/47.0" from the "building automation" line, etc.
1
That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
– 610Drew
Nov 16 at 21:02
add a comment |
up vote
4
down vote
Here's a command you could use:
:g/^,/norm 0kyt,jP
This uses the "global" command. Here's what it basically does:
:g/<regex>/<command>
will run "command" on every single line that matches the "regex". Our regex is pretty simple: Any line that starts with (^
) a comma (,
).
The command:
norm 0kyt,jP
norm
means "run these characters like I typed them in normal mode". So 0k
goes to the beginning of the last line with a comma. yt,
is yank until ,
. jP
goes back to the line we matched on and pastes from the clipboard before the comma.
Conveniently, this runs each line in order, so it works on multiple entryless lines in a row, such as
,Building-Automation,75
,CobraNet,156
,First-Floor-Management,19
,First-Floor-Pavilion,11
,First-Floor-Security,13
,First-Floor-Users,10
,Guest-Wired,3
,Video,150
,Voice_First_Floor,18
,Wireless-Corp,410
,Wireless-Guest,420
,Wireless-Mtg,400
,Wireless-Voice,430
This is because on the "building automation" line, it will grab the "ge-0/0/47.0" from the previous line, and then paste it on this line. Then, on the "cobraNet" line, it will grab the new "ge-0/0/47.0" from the "building automation" line, etc.
1
That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
– 610Drew
Nov 16 at 21:02
add a comment |
up vote
4
down vote
up vote
4
down vote
Here's a command you could use:
:g/^,/norm 0kyt,jP
This uses the "global" command. Here's what it basically does:
:g/<regex>/<command>
will run "command" on every single line that matches the "regex". Our regex is pretty simple: Any line that starts with (^
) a comma (,
).
The command:
norm 0kyt,jP
norm
means "run these characters like I typed them in normal mode". So 0k
goes to the beginning of the last line with a comma. yt,
is yank until ,
. jP
goes back to the line we matched on and pastes from the clipboard before the comma.
Conveniently, this runs each line in order, so it works on multiple entryless lines in a row, such as
,Building-Automation,75
,CobraNet,156
,First-Floor-Management,19
,First-Floor-Pavilion,11
,First-Floor-Security,13
,First-Floor-Users,10
,Guest-Wired,3
,Video,150
,Voice_First_Floor,18
,Wireless-Corp,410
,Wireless-Guest,420
,Wireless-Mtg,400
,Wireless-Voice,430
This is because on the "building automation" line, it will grab the "ge-0/0/47.0" from the previous line, and then paste it on this line. Then, on the "cobraNet" line, it will grab the new "ge-0/0/47.0" from the "building automation" line, etc.
Here's a command you could use:
:g/^,/norm 0kyt,jP
This uses the "global" command. Here's what it basically does:
:g/<regex>/<command>
will run "command" on every single line that matches the "regex". Our regex is pretty simple: Any line that starts with (^
) a comma (,
).
The command:
norm 0kyt,jP
norm
means "run these characters like I typed them in normal mode". So 0k
goes to the beginning of the last line with a comma. yt,
is yank until ,
. jP
goes back to the line we matched on and pastes from the clipboard before the comma.
Conveniently, this runs each line in order, so it works on multiple entryless lines in a row, such as
,Building-Automation,75
,CobraNet,156
,First-Floor-Management,19
,First-Floor-Pavilion,11
,First-Floor-Security,13
,First-Floor-Users,10
,Guest-Wired,3
,Video,150
,Voice_First_Floor,18
,Wireless-Corp,410
,Wireless-Guest,420
,Wireless-Mtg,400
,Wireless-Voice,430
This is because on the "building automation" line, it will grab the "ge-0/0/47.0" from the previous line, and then paste it on this line. Then, on the "cobraNet" line, it will grab the new "ge-0/0/47.0" from the "building automation" line, etc.
answered Nov 16 at 20:57
DJMcMayhem♦
10.1k12860
10.1k12860
1
That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
– 610Drew
Nov 16 at 21:02
add a comment |
1
That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
– 610Drew
Nov 16 at 21:02
1
1
That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
– 610Drew
Nov 16 at 21:02
That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
– 610Drew
Nov 16 at 21:02
add a comment |
610Drew is a new contributor. Be nice, and check out our Code of Conduct.
610Drew is a new contributor. Be nice, and check out our Code of Conduct.
610Drew is a new contributor. Be nice, and check out our Code of Conduct.
610Drew is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f17986%2freplace-with-text-from-the-line-above%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown