How to Sed or Grep number next to text
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a file like the one below. I want to return the value to the right of info2. Secondly I would want to return the value of info5 in the same manner.
FILE:
info1 218, info2 111, info3 415, info5 done,
shell-script sed grep regular-expression
add a comment |Â
up vote
0
down vote
favorite
I have a file like the one below. I want to return the value to the right of info2. Secondly I would want to return the value of info5 in the same manner.
FILE:
info1 218, info2 111, info3 415, info5 done,
shell-script sed grep regular-expression
3
I think awk is a better tool for this.
â NickD
Jan 30 at 19:51
Isinfo1
always in the first field? Isinfo5
always in the fourth field? How big is the file? Are you going to do this once and then you are done? Or are you going to be repeating it? How often?
â NickD
Jan 30 at 19:58
They are not always in the same place unfortunately. I am planning to run this about once an hour for a couple weeks.
â james
Jan 30 at 20:09
1
Do they occur on every line (or at least on most lines)? If so, DopeGhoti's solution in a comment below should work fine. If they are very rare, then you might want to run agrep "info[25]"
in the pipeline instead of hiscat
.
â NickD
Jan 30 at 20:22
If you're happy with one or several of the answers, upvote them. If one is solving your issue, accepting it would be the best way of saying "Thank You!" Accepting an answer also indicates to future readers that the answer actually solved the problem.
â Kusalananda
Feb 7 at 10:56
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a file like the one below. I want to return the value to the right of info2. Secondly I would want to return the value of info5 in the same manner.
FILE:
info1 218, info2 111, info3 415, info5 done,
shell-script sed grep regular-expression
I have a file like the one below. I want to return the value to the right of info2. Secondly I would want to return the value of info5 in the same manner.
FILE:
info1 218, info2 111, info3 415, info5 done,
shell-script sed grep regular-expression
edited Jan 30 at 19:50
Jeff Schaller
31.4k846105
31.4k846105
asked Jan 30 at 19:43
james
1
1
3
I think awk is a better tool for this.
â NickD
Jan 30 at 19:51
Isinfo1
always in the first field? Isinfo5
always in the fourth field? How big is the file? Are you going to do this once and then you are done? Or are you going to be repeating it? How often?
â NickD
Jan 30 at 19:58
They are not always in the same place unfortunately. I am planning to run this about once an hour for a couple weeks.
â james
Jan 30 at 20:09
1
Do they occur on every line (or at least on most lines)? If so, DopeGhoti's solution in a comment below should work fine. If they are very rare, then you might want to run agrep "info[25]"
in the pipeline instead of hiscat
.
â NickD
Jan 30 at 20:22
If you're happy with one or several of the answers, upvote them. If one is solving your issue, accepting it would be the best way of saying "Thank You!" Accepting an answer also indicates to future readers that the answer actually solved the problem.
â Kusalananda
Feb 7 at 10:56
add a comment |Â
3
I think awk is a better tool for this.
â NickD
Jan 30 at 19:51
Isinfo1
always in the first field? Isinfo5
always in the fourth field? How big is the file? Are you going to do this once and then you are done? Or are you going to be repeating it? How often?
â NickD
Jan 30 at 19:58
They are not always in the same place unfortunately. I am planning to run this about once an hour for a couple weeks.
â james
Jan 30 at 20:09
1
Do they occur on every line (or at least on most lines)? If so, DopeGhoti's solution in a comment below should work fine. If they are very rare, then you might want to run agrep "info[25]"
in the pipeline instead of hiscat
.
â NickD
Jan 30 at 20:22
If you're happy with one or several of the answers, upvote them. If one is solving your issue, accepting it would be the best way of saying "Thank You!" Accepting an answer also indicates to future readers that the answer actually solved the problem.
â Kusalananda
Feb 7 at 10:56
3
3
I think awk is a better tool for this.
â NickD
Jan 30 at 19:51
I think awk is a better tool for this.
â NickD
Jan 30 at 19:51
Is
info1
always in the first field? Is info5
always in the fourth field? How big is the file? Are you going to do this once and then you are done? Or are you going to be repeating it? How often?â NickD
Jan 30 at 19:58
Is
info1
always in the first field? Is info5
always in the fourth field? How big is the file? Are you going to do this once and then you are done? Or are you going to be repeating it? How often?â NickD
Jan 30 at 19:58
They are not always in the same place unfortunately. I am planning to run this about once an hour for a couple weeks.
â james
Jan 30 at 20:09
They are not always in the same place unfortunately. I am planning to run this about once an hour for a couple weeks.
â james
Jan 30 at 20:09
1
1
Do they occur on every line (or at least on most lines)? If so, DopeGhoti's solution in a comment below should work fine. If they are very rare, then you might want to run a
grep "info[25]"
in the pipeline instead of his cat
.â NickD
Jan 30 at 20:22
Do they occur on every line (or at least on most lines)? If so, DopeGhoti's solution in a comment below should work fine. If they are very rare, then you might want to run a
grep "info[25]"
in the pipeline instead of his cat
.â NickD
Jan 30 at 20:22
If you're happy with one or several of the answers, upvote them. If one is solving your issue, accepting it would be the best way of saying "Thank You!" Accepting an answer also indicates to future readers that the answer actually solved the problem.
â Kusalananda
Feb 7 at 10:56
If you're happy with one or several of the answers, upvote them. If one is solving your issue, accepting it would be the best way of saying "Thank You!" Accepting an answer also indicates to future readers that the answer actually solved the problem.
â Kusalananda
Feb 7 at 10:56
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
2
down vote
With awk
:
$ awk 'BEGIN RS="," $1 ~ /info[25]$/ print $2 ' input
111
done
We set the input record separator (RS
) to the comma, and then for each record in which the first field contains info
followed by either a two or a five (and nothing else), print the second field.
add a comment |Â
up vote
0
down vote
A slight improvement on chorobaâÂÂs answer:
sed -n 's/.*info2 ([^,]*).*/1/p' file
-n
means âÂÂdonâÂÂt print anything
except when specifically commanded to do soâÂÂ.ÃÂ
This is (somewhat) equivalent to chorobaâÂÂs use of!d
to delete (ignore) lines that donâÂÂt matchinfo2
.- The guts of the command is very similar to chorobaâÂÂs,
except it captures a sequence of any characters except commas
(not just numerals), so it can extract thedone
frominfo5ÃÂ done,
. - The command ends with
p
(print),
because otherwise, with the-n
, nothing would be printed.
This has the advantage that
it doesnâÂÂt require specifying the infoN
label twice.ÃÂ
(And it doesnâÂÂt generate undesired results
if a line contains info20
, info21
, etc.)
add a comment |Â
up vote
0
down vote
A two step solution:
tr ',' 'n' <file | sed -n 's/^ *info[25] *//p'
The tr
transforms the example text into
info1 218
info2 111
info3 415
info5 done
and the sed
script removes the info2
and info5
strings (and any surrounding whitespace), leaving the wanted pieces of text. The other lines are discarded.
Result:
111
done
This is better done with awk
, as in DopeGhoti's solution.
An awk
variation based on my tr
approach:
tr ',' 'n' <file | awk '/info[25]/ print $2 '
you actually don't need tr if you use awk, look at the answer by @DopeGhoti
â Diego Roccia
Feb 2 at 17:14
@DiegoRoccia I'm well aware of his answer (otherwise I would not link to it). This is a variation an mysed
solution, and as you can see, it replaces his setting ofRS
with preprocessing the data into newline-delimited records. The two are otherwise the same.
â Kusalananda
Feb 2 at 18:00
I agree that the output is the same, but IMO adding useless complexity is not a good variation, so I'm advising not to do it
â Diego Roccia
Feb 9 at 9:47
add a comment |Â
up vote
-1
down vote
You can use sed:
sed '/info2 [0-9]/!d;s/.*info2 ([0-9]*).*/1/' file
/info2/
is an "address", any line containinginfo2
is considered to match the address.!d
means "delete lines outside of the address", so only lines containinginfo2
will be processed by the next command.- The substitution uses a capture group to remember the number after
info2
, and the whole line (everything beforeinfo2
,info2
itself, the number, and anything following the number) is replaced by the number.
If you need to capture "done" after info5
, you can't use [0-9]*
, but you can replace it by [^,]*
, i.e. non-comma.
... and he wants to do the same thing with info5 (and the value there is not a number).
â NickD
Jan 30 at 19:50
@Nick (just to make the answer complete) use[^,]*
in place of[0-9]*
, and I agreeawk
is a better fit.
â Weijun Zhou
Jan 30 at 19:57
What would Awk look like and why better?
â james
Jan 30 at 19:59
This generates undesired results if a line containsinfo2
without actually having aninfo2
label; e.g.,â¯info20
,info21
, etc.
â G-Man
Jan 31 at 2:03
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
With awk
:
$ awk 'BEGIN RS="," $1 ~ /info[25]$/ print $2 ' input
111
done
We set the input record separator (RS
) to the comma, and then for each record in which the first field contains info
followed by either a two or a five (and nothing else), print the second field.
add a comment |Â
up vote
2
down vote
With awk
:
$ awk 'BEGIN RS="," $1 ~ /info[25]$/ print $2 ' input
111
done
We set the input record separator (RS
) to the comma, and then for each record in which the first field contains info
followed by either a two or a five (and nothing else), print the second field.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
With awk
:
$ awk 'BEGIN RS="," $1 ~ /info[25]$/ print $2 ' input
111
done
We set the input record separator (RS
) to the comma, and then for each record in which the first field contains info
followed by either a two or a five (and nothing else), print the second field.
With awk
:
$ awk 'BEGIN RS="," $1 ~ /info[25]$/ print $2 ' input
111
done
We set the input record separator (RS
) to the comma, and then for each record in which the first field contains info
followed by either a two or a five (and nothing else), print the second field.
answered Jan 30 at 20:21
DopeGhoti
40.4k54879
40.4k54879
add a comment |Â
add a comment |Â
up vote
0
down vote
A slight improvement on chorobaâÂÂs answer:
sed -n 's/.*info2 ([^,]*).*/1/p' file
-n
means âÂÂdonâÂÂt print anything
except when specifically commanded to do soâÂÂ.ÃÂ
This is (somewhat) equivalent to chorobaâÂÂs use of!d
to delete (ignore) lines that donâÂÂt matchinfo2
.- The guts of the command is very similar to chorobaâÂÂs,
except it captures a sequence of any characters except commas
(not just numerals), so it can extract thedone
frominfo5ÃÂ done,
. - The command ends with
p
(print),
because otherwise, with the-n
, nothing would be printed.
This has the advantage that
it doesnâÂÂt require specifying the infoN
label twice.ÃÂ
(And it doesnâÂÂt generate undesired results
if a line contains info20
, info21
, etc.)
add a comment |Â
up vote
0
down vote
A slight improvement on chorobaâÂÂs answer:
sed -n 's/.*info2 ([^,]*).*/1/p' file
-n
means âÂÂdonâÂÂt print anything
except when specifically commanded to do soâÂÂ.ÃÂ
This is (somewhat) equivalent to chorobaâÂÂs use of!d
to delete (ignore) lines that donâÂÂt matchinfo2
.- The guts of the command is very similar to chorobaâÂÂs,
except it captures a sequence of any characters except commas
(not just numerals), so it can extract thedone
frominfo5ÃÂ done,
. - The command ends with
p
(print),
because otherwise, with the-n
, nothing would be printed.
This has the advantage that
it doesnâÂÂt require specifying the infoN
label twice.ÃÂ
(And it doesnâÂÂt generate undesired results
if a line contains info20
, info21
, etc.)
add a comment |Â
up vote
0
down vote
up vote
0
down vote
A slight improvement on chorobaâÂÂs answer:
sed -n 's/.*info2 ([^,]*).*/1/p' file
-n
means âÂÂdonâÂÂt print anything
except when specifically commanded to do soâÂÂ.ÃÂ
This is (somewhat) equivalent to chorobaâÂÂs use of!d
to delete (ignore) lines that donâÂÂt matchinfo2
.- The guts of the command is very similar to chorobaâÂÂs,
except it captures a sequence of any characters except commas
(not just numerals), so it can extract thedone
frominfo5ÃÂ done,
. - The command ends with
p
(print),
because otherwise, with the-n
, nothing would be printed.
This has the advantage that
it doesnâÂÂt require specifying the infoN
label twice.ÃÂ
(And it doesnâÂÂt generate undesired results
if a line contains info20
, info21
, etc.)
A slight improvement on chorobaâÂÂs answer:
sed -n 's/.*info2 ([^,]*).*/1/p' file
-n
means âÂÂdonâÂÂt print anything
except when specifically commanded to do soâÂÂ.ÃÂ
This is (somewhat) equivalent to chorobaâÂÂs use of!d
to delete (ignore) lines that donâÂÂt matchinfo2
.- The guts of the command is very similar to chorobaâÂÂs,
except it captures a sequence of any characters except commas
(not just numerals), so it can extract thedone
frominfo5ÃÂ done,
. - The command ends with
p
(print),
because otherwise, with the-n
, nothing would be printed.
This has the advantage that
it doesnâÂÂt require specifying the infoN
label twice.ÃÂ
(And it doesnâÂÂt generate undesired results
if a line contains info20
, info21
, etc.)
answered Jan 31 at 2:01
G-Man
11.5k82657
11.5k82657
add a comment |Â
add a comment |Â
up vote
0
down vote
A two step solution:
tr ',' 'n' <file | sed -n 's/^ *info[25] *//p'
The tr
transforms the example text into
info1 218
info2 111
info3 415
info5 done
and the sed
script removes the info2
and info5
strings (and any surrounding whitespace), leaving the wanted pieces of text. The other lines are discarded.
Result:
111
done
This is better done with awk
, as in DopeGhoti's solution.
An awk
variation based on my tr
approach:
tr ',' 'n' <file | awk '/info[25]/ print $2 '
you actually don't need tr if you use awk, look at the answer by @DopeGhoti
â Diego Roccia
Feb 2 at 17:14
@DiegoRoccia I'm well aware of his answer (otherwise I would not link to it). This is a variation an mysed
solution, and as you can see, it replaces his setting ofRS
with preprocessing the data into newline-delimited records. The two are otherwise the same.
â Kusalananda
Feb 2 at 18:00
I agree that the output is the same, but IMO adding useless complexity is not a good variation, so I'm advising not to do it
â Diego Roccia
Feb 9 at 9:47
add a comment |Â
up vote
0
down vote
A two step solution:
tr ',' 'n' <file | sed -n 's/^ *info[25] *//p'
The tr
transforms the example text into
info1 218
info2 111
info3 415
info5 done
and the sed
script removes the info2
and info5
strings (and any surrounding whitespace), leaving the wanted pieces of text. The other lines are discarded.
Result:
111
done
This is better done with awk
, as in DopeGhoti's solution.
An awk
variation based on my tr
approach:
tr ',' 'n' <file | awk '/info[25]/ print $2 '
you actually don't need tr if you use awk, look at the answer by @DopeGhoti
â Diego Roccia
Feb 2 at 17:14
@DiegoRoccia I'm well aware of his answer (otherwise I would not link to it). This is a variation an mysed
solution, and as you can see, it replaces his setting ofRS
with preprocessing the data into newline-delimited records. The two are otherwise the same.
â Kusalananda
Feb 2 at 18:00
I agree that the output is the same, but IMO adding useless complexity is not a good variation, so I'm advising not to do it
â Diego Roccia
Feb 9 at 9:47
add a comment |Â
up vote
0
down vote
up vote
0
down vote
A two step solution:
tr ',' 'n' <file | sed -n 's/^ *info[25] *//p'
The tr
transforms the example text into
info1 218
info2 111
info3 415
info5 done
and the sed
script removes the info2
and info5
strings (and any surrounding whitespace), leaving the wanted pieces of text. The other lines are discarded.
Result:
111
done
This is better done with awk
, as in DopeGhoti's solution.
An awk
variation based on my tr
approach:
tr ',' 'n' <file | awk '/info[25]/ print $2 '
A two step solution:
tr ',' 'n' <file | sed -n 's/^ *info[25] *//p'
The tr
transforms the example text into
info1 218
info2 111
info3 415
info5 done
and the sed
script removes the info2
and info5
strings (and any surrounding whitespace), leaving the wanted pieces of text. The other lines are discarded.
Result:
111
done
This is better done with awk
, as in DopeGhoti's solution.
An awk
variation based on my tr
approach:
tr ',' 'n' <file | awk '/info[25]/ print $2 '
answered Feb 2 at 15:53
Kusalananda
103k13202318
103k13202318
you actually don't need tr if you use awk, look at the answer by @DopeGhoti
â Diego Roccia
Feb 2 at 17:14
@DiegoRoccia I'm well aware of his answer (otherwise I would not link to it). This is a variation an mysed
solution, and as you can see, it replaces his setting ofRS
with preprocessing the data into newline-delimited records. The two are otherwise the same.
â Kusalananda
Feb 2 at 18:00
I agree that the output is the same, but IMO adding useless complexity is not a good variation, so I'm advising not to do it
â Diego Roccia
Feb 9 at 9:47
add a comment |Â
you actually don't need tr if you use awk, look at the answer by @DopeGhoti
â Diego Roccia
Feb 2 at 17:14
@DiegoRoccia I'm well aware of his answer (otherwise I would not link to it). This is a variation an mysed
solution, and as you can see, it replaces his setting ofRS
with preprocessing the data into newline-delimited records. The two are otherwise the same.
â Kusalananda
Feb 2 at 18:00
I agree that the output is the same, but IMO adding useless complexity is not a good variation, so I'm advising not to do it
â Diego Roccia
Feb 9 at 9:47
you actually don't need tr if you use awk, look at the answer by @DopeGhoti
â Diego Roccia
Feb 2 at 17:14
you actually don't need tr if you use awk, look at the answer by @DopeGhoti
â Diego Roccia
Feb 2 at 17:14
@DiegoRoccia I'm well aware of his answer (otherwise I would not link to it). This is a variation an my
sed
solution, and as you can see, it replaces his setting of RS
with preprocessing the data into newline-delimited records. The two are otherwise the same.â Kusalananda
Feb 2 at 18:00
@DiegoRoccia I'm well aware of his answer (otherwise I would not link to it). This is a variation an my
sed
solution, and as you can see, it replaces his setting of RS
with preprocessing the data into newline-delimited records. The two are otherwise the same.â Kusalananda
Feb 2 at 18:00
I agree that the output is the same, but IMO adding useless complexity is not a good variation, so I'm advising not to do it
â Diego Roccia
Feb 9 at 9:47
I agree that the output is the same, but IMO adding useless complexity is not a good variation, so I'm advising not to do it
â Diego Roccia
Feb 9 at 9:47
add a comment |Â
up vote
-1
down vote
You can use sed:
sed '/info2 [0-9]/!d;s/.*info2 ([0-9]*).*/1/' file
/info2/
is an "address", any line containinginfo2
is considered to match the address.!d
means "delete lines outside of the address", so only lines containinginfo2
will be processed by the next command.- The substitution uses a capture group to remember the number after
info2
, and the whole line (everything beforeinfo2
,info2
itself, the number, and anything following the number) is replaced by the number.
If you need to capture "done" after info5
, you can't use [0-9]*
, but you can replace it by [^,]*
, i.e. non-comma.
... and he wants to do the same thing with info5 (and the value there is not a number).
â NickD
Jan 30 at 19:50
@Nick (just to make the answer complete) use[^,]*
in place of[0-9]*
, and I agreeawk
is a better fit.
â Weijun Zhou
Jan 30 at 19:57
What would Awk look like and why better?
â james
Jan 30 at 19:59
This generates undesired results if a line containsinfo2
without actually having aninfo2
label; e.g.,â¯info20
,info21
, etc.
â G-Man
Jan 31 at 2:03
add a comment |Â
up vote
-1
down vote
You can use sed:
sed '/info2 [0-9]/!d;s/.*info2 ([0-9]*).*/1/' file
/info2/
is an "address", any line containinginfo2
is considered to match the address.!d
means "delete lines outside of the address", so only lines containinginfo2
will be processed by the next command.- The substitution uses a capture group to remember the number after
info2
, and the whole line (everything beforeinfo2
,info2
itself, the number, and anything following the number) is replaced by the number.
If you need to capture "done" after info5
, you can't use [0-9]*
, but you can replace it by [^,]*
, i.e. non-comma.
... and he wants to do the same thing with info5 (and the value there is not a number).
â NickD
Jan 30 at 19:50
@Nick (just to make the answer complete) use[^,]*
in place of[0-9]*
, and I agreeawk
is a better fit.
â Weijun Zhou
Jan 30 at 19:57
What would Awk look like and why better?
â james
Jan 30 at 19:59
This generates undesired results if a line containsinfo2
without actually having aninfo2
label; e.g.,â¯info20
,info21
, etc.
â G-Man
Jan 31 at 2:03
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
You can use sed:
sed '/info2 [0-9]/!d;s/.*info2 ([0-9]*).*/1/' file
/info2/
is an "address", any line containinginfo2
is considered to match the address.!d
means "delete lines outside of the address", so only lines containinginfo2
will be processed by the next command.- The substitution uses a capture group to remember the number after
info2
, and the whole line (everything beforeinfo2
,info2
itself, the number, and anything following the number) is replaced by the number.
If you need to capture "done" after info5
, you can't use [0-9]*
, but you can replace it by [^,]*
, i.e. non-comma.
You can use sed:
sed '/info2 [0-9]/!d;s/.*info2 ([0-9]*).*/1/' file
/info2/
is an "address", any line containinginfo2
is considered to match the address.!d
means "delete lines outside of the address", so only lines containinginfo2
will be processed by the next command.- The substitution uses a capture group to remember the number after
info2
, and the whole line (everything beforeinfo2
,info2
itself, the number, and anything following the number) is replaced by the number.
If you need to capture "done" after info5
, you can't use [0-9]*
, but you can replace it by [^,]*
, i.e. non-comma.
edited Jan 31 at 9:58
answered Jan 30 at 19:48
choroba
24.3k33967
24.3k33967
... and he wants to do the same thing with info5 (and the value there is not a number).
â NickD
Jan 30 at 19:50
@Nick (just to make the answer complete) use[^,]*
in place of[0-9]*
, and I agreeawk
is a better fit.
â Weijun Zhou
Jan 30 at 19:57
What would Awk look like and why better?
â james
Jan 30 at 19:59
This generates undesired results if a line containsinfo2
without actually having aninfo2
label; e.g.,â¯info20
,info21
, etc.
â G-Man
Jan 31 at 2:03
add a comment |Â
... and he wants to do the same thing with info5 (and the value there is not a number).
â NickD
Jan 30 at 19:50
@Nick (just to make the answer complete) use[^,]*
in place of[0-9]*
, and I agreeawk
is a better fit.
â Weijun Zhou
Jan 30 at 19:57
What would Awk look like and why better?
â james
Jan 30 at 19:59
This generates undesired results if a line containsinfo2
without actually having aninfo2
label; e.g.,â¯info20
,info21
, etc.
â G-Man
Jan 31 at 2:03
... and he wants to do the same thing with info5 (and the value there is not a number).
â NickD
Jan 30 at 19:50
... and he wants to do the same thing with info5 (and the value there is not a number).
â NickD
Jan 30 at 19:50
@Nick (just to make the answer complete) use
[^,]*
in place of [0-9]*
, and I agree awk
is a better fit.â Weijun Zhou
Jan 30 at 19:57
@Nick (just to make the answer complete) use
[^,]*
in place of [0-9]*
, and I agree awk
is a better fit.â Weijun Zhou
Jan 30 at 19:57
What would Awk look like and why better?
â james
Jan 30 at 19:59
What would Awk look like and why better?
â james
Jan 30 at 19:59
This generates undesired results if a line contains
info2
without actually having an info2
label; e.g.,â¯info20
, info21
, etc.â G-Man
Jan 31 at 2:03
This generates undesired results if a line contains
info2
without actually having an info2
label; e.g.,â¯info20
, info21
, etc.â G-Man
Jan 31 at 2:03
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420776%2fhow-to-sed-or-grep-number-next-to-text%23new-answer', 'question_page');
);
Post as a guest
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
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
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
3
I think awk is a better tool for this.
â NickD
Jan 30 at 19:51
Is
info1
always in the first field? Isinfo5
always in the fourth field? How big is the file? Are you going to do this once and then you are done? Or are you going to be repeating it? How often?â NickD
Jan 30 at 19:58
They are not always in the same place unfortunately. I am planning to run this about once an hour for a couple weeks.
â james
Jan 30 at 20:09
1
Do they occur on every line (or at least on most lines)? If so, DopeGhoti's solution in a comment below should work fine. If they are very rare, then you might want to run a
grep "info[25]"
in the pipeline instead of hiscat
.â NickD
Jan 30 at 20:22
If you're happy with one or several of the answers, upvote them. If one is solving your issue, accepting it would be the best way of saying "Thank You!" Accepting an answer also indicates to future readers that the answer actually solved the problem.
â Kusalananda
Feb 7 at 10:56