How do i get multiple number strings after brackets [] using sed or awk2019 Community Moderator ElectionHow can I remove the first line of a text file using bash/sed script?What are the differences between Perl, Python, AWK and sed?Escape a string for a sed replace patternHow can I replace a newline (n) using sed?How to do a recursive find/replace of a string with awk or sed?What is the difference between sed and awk?Insert a line at specific line number with sed or awkWhat are the differences among grep, awk & sed?AWK multiple delimiterserialized numbers in text files with for loop and sed
When two POV characters meet
Extension of Splitting Fields over An Arbitrary Field
Best mythical creature to use as livestock?
Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?
My adviser wants to be the first author
Why does Deadpool say "You're welcome, Canada," after shooting Ryan Reynolds in the end credits?
Good allowance savings plan?
When were linguistics departments first established
What exactly is the purpose of connection links straped between the rocket and the launch pad
Can the druid cantrip Thorn Whip really defeat a water weird this easily?
Coworker uses her breast-pump everywhere in the office
Potentiometer like component
Best approach to update all entries in a list that is paginated?
What is the dot in “1.2.4."
Want to switch to tankless, but can I use my existing wiring?
Why must traveling waves have the same amplitude to form a standing wave?
Is "history" a male-biased word ("his+story")?
What Happens when Passenger Refuses to Fly Boeing 737 Max?
Does Linux have system calls to access all the features of the file systems it supports?
How can I discourage/prevent PCs from using door choke-points?
What does it mean when multiple 々 marks follow a 、?
Can infringement of a trademark be pursued for using a company's name in a sentence?
Is it illegal in Germany to take sick leave if you caused your own illness with food?
Should QA ask requirements to developers?
How do i get multiple number strings after brackets [] using sed or awk
2019 Community Moderator ElectionHow can I remove the first line of a text file using bash/sed script?What are the differences between Perl, Python, AWK and sed?Escape a string for a sed replace patternHow can I replace a newline (n) using sed?How to do a recursive find/replace of a string with awk or sed?What is the difference between sed and awk?Insert a line at specific line number with sed or awkWhat are the differences among grep, awk & sed?AWK multiple delimiterserialized numbers in text files with for loop and sed
I have a file with 2k data as below .I want to get only number values of updr/udrl/imgr/imgl fields as 41110.00 120 996.00 523 with tab separated where updr/updl/imgr/imgl fileds present.
I have tried with single pattern replacement till brackets but after that not able to apply another pattern to get numbers.
echo `sed -n 's/^[.*][^0-9]*[[:space:]]* //p' client_stat.txt > client_stat_onlyData.csv` ; echo `sed -i 's/ /t/g' client_stat_onlyData.csv`
I am getting o/p as like below but i do not want to print udpr/updl/imgr/imgl strings i want to print only number values.
updr 48358.00 updl 120 imgr 1015.00 imgl 523
updr 48562.00 updl 120 imgr 1169.00 imgl 523
updr 48305.00 updl 121 imgr 1210.00 imgl 523
updr 48285.00 updl 121 imgr 1135.00 imgl 523
updr 48459.00 updl 121 imgr 1210.00 imgl 523
updr 48246.00 updl 120 imgr 881.00 imgl 523
updr 48439.00 updl 120 imgr 1109.00 imgl 523
Number of Connection Count = 1
Creating RSSL connection Host: 192.168.120.1 Port: 14002
UPA server component version: ads3.2.2.L1.linux.tis.rrg 64-bit
Setting rmds connection 0x10a8900
Connection list count is 1
SupportStandby: 0
SupportBatchRequests Initial Open: Yes
SupportBatchRequests Reissue: Yes
SupportBatchClose: Yes
SupportViewRequests: Yes
SupportOptimizedPauseResume: 0
[Tue Feb 19 14:42:50.415] updr 41110.00 updl 120 imgr 996.00 imgl 523
[Tue Feb 19 14:42:51.415] updr 49368.00 updl 121 imgr 845.00 imgl 523
Status Received <388> Status Text: Stale Status for Item REC1000017 Text: F7: Item Preempted
[Tue Feb 19 14:42:52.415] updr 48542.00 updl 121 imgr 1170.00 imgl 523
Status Received <1166> Status Text: Stale Status for Item REC1000410 Text: F7: Item Preempted
[Tue Feb 19 14:42:53.415] updr 47942.00 updl 120 imgr 1133.00 imgl 523
Status Received <1133> Status Text: Stale Status for Item REC1001609 Text: F7: Item Preempted
[Tue Feb 19 14:42:54.415] updr 48513.00 updl 120 imgr 1100.00 imgl 523
awk sed
New contributor
add a comment |
I have a file with 2k data as below .I want to get only number values of updr/udrl/imgr/imgl fields as 41110.00 120 996.00 523 with tab separated where updr/updl/imgr/imgl fileds present.
I have tried with single pattern replacement till brackets but after that not able to apply another pattern to get numbers.
echo `sed -n 's/^[.*][^0-9]*[[:space:]]* //p' client_stat.txt > client_stat_onlyData.csv` ; echo `sed -i 's/ /t/g' client_stat_onlyData.csv`
I am getting o/p as like below but i do not want to print udpr/updl/imgr/imgl strings i want to print only number values.
updr 48358.00 updl 120 imgr 1015.00 imgl 523
updr 48562.00 updl 120 imgr 1169.00 imgl 523
updr 48305.00 updl 121 imgr 1210.00 imgl 523
updr 48285.00 updl 121 imgr 1135.00 imgl 523
updr 48459.00 updl 121 imgr 1210.00 imgl 523
updr 48246.00 updl 120 imgr 881.00 imgl 523
updr 48439.00 updl 120 imgr 1109.00 imgl 523
Number of Connection Count = 1
Creating RSSL connection Host: 192.168.120.1 Port: 14002
UPA server component version: ads3.2.2.L1.linux.tis.rrg 64-bit
Setting rmds connection 0x10a8900
Connection list count is 1
SupportStandby: 0
SupportBatchRequests Initial Open: Yes
SupportBatchRequests Reissue: Yes
SupportBatchClose: Yes
SupportViewRequests: Yes
SupportOptimizedPauseResume: 0
[Tue Feb 19 14:42:50.415] updr 41110.00 updl 120 imgr 996.00 imgl 523
[Tue Feb 19 14:42:51.415] updr 49368.00 updl 121 imgr 845.00 imgl 523
Status Received <388> Status Text: Stale Status for Item REC1000017 Text: F7: Item Preempted
[Tue Feb 19 14:42:52.415] updr 48542.00 updl 121 imgr 1170.00 imgl 523
Status Received <1166> Status Text: Stale Status for Item REC1000410 Text: F7: Item Preempted
[Tue Feb 19 14:42:53.415] updr 47942.00 updl 120 imgr 1133.00 imgl 523
Status Received <1133> Status Text: Stale Status for Item REC1001609 Text: F7: Item Preempted
[Tue Feb 19 14:42:54.415] updr 48513.00 updl 120 imgr 1100.00 imgl 523
awk sed
New contributor
A warm welcome to SO, special thanks for adding whatever you have tried and provding the samples of input and expected output. You almost posted a ideal post, only thing missed is CODE TAGS, please do wrap your samples with code tags usingbutton of your post(whch you did partially too, you need to cover al samples with it), keep learning and keep sharing on this GREAT site SO, cheers.
– RavinderSingh13
Mar 7 at 10:54
add a comment |
I have a file with 2k data as below .I want to get only number values of updr/udrl/imgr/imgl fields as 41110.00 120 996.00 523 with tab separated where updr/updl/imgr/imgl fileds present.
I have tried with single pattern replacement till brackets but after that not able to apply another pattern to get numbers.
echo `sed -n 's/^[.*][^0-9]*[[:space:]]* //p' client_stat.txt > client_stat_onlyData.csv` ; echo `sed -i 's/ /t/g' client_stat_onlyData.csv`
I am getting o/p as like below but i do not want to print udpr/updl/imgr/imgl strings i want to print only number values.
updr 48358.00 updl 120 imgr 1015.00 imgl 523
updr 48562.00 updl 120 imgr 1169.00 imgl 523
updr 48305.00 updl 121 imgr 1210.00 imgl 523
updr 48285.00 updl 121 imgr 1135.00 imgl 523
updr 48459.00 updl 121 imgr 1210.00 imgl 523
updr 48246.00 updl 120 imgr 881.00 imgl 523
updr 48439.00 updl 120 imgr 1109.00 imgl 523
Number of Connection Count = 1
Creating RSSL connection Host: 192.168.120.1 Port: 14002
UPA server component version: ads3.2.2.L1.linux.tis.rrg 64-bit
Setting rmds connection 0x10a8900
Connection list count is 1
SupportStandby: 0
SupportBatchRequests Initial Open: Yes
SupportBatchRequests Reissue: Yes
SupportBatchClose: Yes
SupportViewRequests: Yes
SupportOptimizedPauseResume: 0
[Tue Feb 19 14:42:50.415] updr 41110.00 updl 120 imgr 996.00 imgl 523
[Tue Feb 19 14:42:51.415] updr 49368.00 updl 121 imgr 845.00 imgl 523
Status Received <388> Status Text: Stale Status for Item REC1000017 Text: F7: Item Preempted
[Tue Feb 19 14:42:52.415] updr 48542.00 updl 121 imgr 1170.00 imgl 523
Status Received <1166> Status Text: Stale Status for Item REC1000410 Text: F7: Item Preempted
[Tue Feb 19 14:42:53.415] updr 47942.00 updl 120 imgr 1133.00 imgl 523
Status Received <1133> Status Text: Stale Status for Item REC1001609 Text: F7: Item Preempted
[Tue Feb 19 14:42:54.415] updr 48513.00 updl 120 imgr 1100.00 imgl 523
awk sed
New contributor
I have a file with 2k data as below .I want to get only number values of updr/udrl/imgr/imgl fields as 41110.00 120 996.00 523 with tab separated where updr/updl/imgr/imgl fileds present.
I have tried with single pattern replacement till brackets but after that not able to apply another pattern to get numbers.
echo `sed -n 's/^[.*][^0-9]*[[:space:]]* //p' client_stat.txt > client_stat_onlyData.csv` ; echo `sed -i 's/ /t/g' client_stat_onlyData.csv`
I am getting o/p as like below but i do not want to print udpr/updl/imgr/imgl strings i want to print only number values.
updr 48358.00 updl 120 imgr 1015.00 imgl 523
updr 48562.00 updl 120 imgr 1169.00 imgl 523
updr 48305.00 updl 121 imgr 1210.00 imgl 523
updr 48285.00 updl 121 imgr 1135.00 imgl 523
updr 48459.00 updl 121 imgr 1210.00 imgl 523
updr 48246.00 updl 120 imgr 881.00 imgl 523
updr 48439.00 updl 120 imgr 1109.00 imgl 523
Number of Connection Count = 1
Creating RSSL connection Host: 192.168.120.1 Port: 14002
UPA server component version: ads3.2.2.L1.linux.tis.rrg 64-bit
Setting rmds connection 0x10a8900
Connection list count is 1
SupportStandby: 0
SupportBatchRequests Initial Open: Yes
SupportBatchRequests Reissue: Yes
SupportBatchClose: Yes
SupportViewRequests: Yes
SupportOptimizedPauseResume: 0
[Tue Feb 19 14:42:50.415] updr 41110.00 updl 120 imgr 996.00 imgl 523
[Tue Feb 19 14:42:51.415] updr 49368.00 updl 121 imgr 845.00 imgl 523
Status Received <388> Status Text: Stale Status for Item REC1000017 Text: F7: Item Preempted
[Tue Feb 19 14:42:52.415] updr 48542.00 updl 121 imgr 1170.00 imgl 523
Status Received <1166> Status Text: Stale Status for Item REC1000410 Text: F7: Item Preempted
[Tue Feb 19 14:42:53.415] updr 47942.00 updl 120 imgr 1133.00 imgl 523
Status Received <1133> Status Text: Stale Status for Item REC1001609 Text: F7: Item Preempted
[Tue Feb 19 14:42:54.415] updr 48513.00 updl 120 imgr 1100.00 imgl 523
awk sed
awk sed
New contributor
New contributor
edited Mar 7 at 10:55
RavinderSingh13
29.7k41639
29.7k41639
New contributor
asked Mar 7 at 10:48
vijaya mvijaya m
61
61
New contributor
New contributor
A warm welcome to SO, special thanks for adding whatever you have tried and provding the samples of input and expected output. You almost posted a ideal post, only thing missed is CODE TAGS, please do wrap your samples with code tags usingbutton of your post(whch you did partially too, you need to cover al samples with it), keep learning and keep sharing on this GREAT site SO, cheers.
– RavinderSingh13
Mar 7 at 10:54
add a comment |
A warm welcome to SO, special thanks for adding whatever you have tried and provding the samples of input and expected output. You almost posted a ideal post, only thing missed is CODE TAGS, please do wrap your samples with code tags usingbutton of your post(whch you did partially too, you need to cover al samples with it), keep learning and keep sharing on this GREAT site SO, cheers.
– RavinderSingh13
Mar 7 at 10:54
A warm welcome to SO, special thanks for adding whatever you have tried and provding the samples of input and expected output. You almost posted a ideal post, only thing missed is CODE TAGS, please do wrap your samples with code tags using
button of your post(whch you did partially too, you need to cover al samples with it), keep learning and keep sharing on this GREAT site SO, cheers.– RavinderSingh13
Mar 7 at 10:54
A warm welcome to SO, special thanks for adding whatever you have tried and provding the samples of input and expected output. You almost posted a ideal post, only thing missed is CODE TAGS, please do wrap your samples with code tags using
button of your post(whch you did partially too, you need to cover al samples with it), keep learning and keep sharing on this GREAT site SO, cheers.– RavinderSingh13
Mar 7 at 10:54
add a comment |
2 Answers
2
active
oldest
votes
Could you please try following(it will show the number next to strings whichever OP mentioned to search for).
awk 'for(i=1;i<=NF;i++)if($i ~ /^(updr;print val;val=""' Input_file
Or adding a non-one liner form of solution.
awk '
for(i=1;i<=NF;i++)
if($i ~ /^(updr
print val
val=""
' Input_file
In case you want to save output ito Input_fie itself append > temp_file && mv temp_file Input_file
in above code. Also in case your Input_file is TAB delimited and you want to have output as TAB delimited format then change awk
to awk 'BEGINFS="OFS="t"
keep from {for....
code as it is as mentioned above.
Explanation: Adding explanation for above code.
awk ' ##Starting awk program here.
##Startig conditions BLOCK here.
for(i=1;i<=NF;i++)imgr ##Closing BLOCK for for loop here.
print val ##Printing value of variable val here.
val="" ##Nullifying variable val value here.
##Closing main BLOCK now.
' Input_file ##Mentioning Input_file name here.
EDIT: Example of run of code.
awk 'for(i=1;i<=NF;i++)if($i ~ /^(updr;print val;val=""' Input_file
48358.00 1015.00 523
48562.00 1169.00 523
48305.00 1210.00 523
48285.00 1135.00 523
48459.00 1210.00 523
48246.00 881.00 523
48439.00 1109.00 523
1
$i ~ /^(updr|udrl|imgr|imgl)$/
?
– jhnc
Mar 7 at 11:15
@jhnc, thank you for letting me know the shortcut, changed solution now, thank you.
– RavinderSingh13
Mar 7 at 11:17
it's also a bugfix,/updr/
matchesasdasdsupdrwqwewe
. :-) For efficiency, you could also do,i++; val = ... $i; i++
– jhnc
Mar 7 at 11:19
@jhnc, thank you for letting know.
– RavinderSingh13
Mar 7 at 11:26
1
oops. secondi++
shouldn't be there. Idea is to skip the regexp check of the field after the current match (as we know that it can't)
– jhnc
Mar 7 at 11:29
|
show 8 more comments
Using Perl one-liner
perl -ne ' while( /(updr|udrl|imgr|imgl)s+(S+)/g ) print "$2 " print "n" ' file
with your given inputs
$ cat vijaya.txt
updr 48358.00 updl 120 imgr 1015.00 imgl 523
updr 48562.00 updl 120 imgr 1169.00 imgl 523
updr 48305.00 updl 121 imgr 1210.00 imgl 523
updr 48285.00 updl 121 imgr 1135.00 imgl 523
updr 48459.00 updl 121 imgr 1210.00 imgl 523
updr 48246.00 updl 120 imgr 881.00 imgl 523
updr 48439.00 updl 120 imgr 1109.00 imgl 523
$ perl -ne ' while( /(updr|udrl|imgr|imgl)s+(S+)/g ) print "$2 " print "n" ' vijaya.txt
48358.00 1015.00 523
48562.00 1169.00 523
48305.00 1210.00 523
48285.00 1135.00 523
48459.00 1210.00 523
48246.00 881.00 523
48439.00 1109.00 523
$
I am looking a command using shell script ...Thanks for your solution in perl it may helpful to others too.
– vijaya m
Mar 11 at 4:50
@ please share a working command in shell script. Still i did not able to crack it.
– vijaya m
Mar 11 at 4:51
It is working with the same logic above only thing is output in the file is after so many lines not at the beginning of the file 49368.00 121 845.00 523 48542.00 121 1170.00 523 echoawk 'BEGIN print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
Thanks guys for your help here is the final command which i was looking to print o/p echoawk ' BEGIN OFS="," ;print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" /updr/ for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
vijaya m 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%2fstackoverflow.com%2fquestions%2f55041969%2fhow-do-i-get-multiple-number-strings-after-brackets-using-sed-or-awk%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Could you please try following(it will show the number next to strings whichever OP mentioned to search for).
awk 'for(i=1;i<=NF;i++)if($i ~ /^(updr;print val;val=""' Input_file
Or adding a non-one liner form of solution.
awk '
for(i=1;i<=NF;i++)
if($i ~ /^(updr
print val
val=""
' Input_file
In case you want to save output ito Input_fie itself append > temp_file && mv temp_file Input_file
in above code. Also in case your Input_file is TAB delimited and you want to have output as TAB delimited format then change awk
to awk 'BEGINFS="OFS="t"
keep from {for....
code as it is as mentioned above.
Explanation: Adding explanation for above code.
awk ' ##Starting awk program here.
##Startig conditions BLOCK here.
for(i=1;i<=NF;i++)imgr ##Closing BLOCK for for loop here.
print val ##Printing value of variable val here.
val="" ##Nullifying variable val value here.
##Closing main BLOCK now.
' Input_file ##Mentioning Input_file name here.
EDIT: Example of run of code.
awk 'for(i=1;i<=NF;i++)if($i ~ /^(updr;print val;val=""' Input_file
48358.00 1015.00 523
48562.00 1169.00 523
48305.00 1210.00 523
48285.00 1135.00 523
48459.00 1210.00 523
48246.00 881.00 523
48439.00 1109.00 523
1
$i ~ /^(updr|udrl|imgr|imgl)$/
?
– jhnc
Mar 7 at 11:15
@jhnc, thank you for letting me know the shortcut, changed solution now, thank you.
– RavinderSingh13
Mar 7 at 11:17
it's also a bugfix,/updr/
matchesasdasdsupdrwqwewe
. :-) For efficiency, you could also do,i++; val = ... $i; i++
– jhnc
Mar 7 at 11:19
@jhnc, thank you for letting know.
– RavinderSingh13
Mar 7 at 11:26
1
oops. secondi++
shouldn't be there. Idea is to skip the regexp check of the field after the current match (as we know that it can't)
– jhnc
Mar 7 at 11:29
|
show 8 more comments
Could you please try following(it will show the number next to strings whichever OP mentioned to search for).
awk 'for(i=1;i<=NF;i++)if($i ~ /^(updr;print val;val=""' Input_file
Or adding a non-one liner form of solution.
awk '
for(i=1;i<=NF;i++)
if($i ~ /^(updr
print val
val=""
' Input_file
In case you want to save output ito Input_fie itself append > temp_file && mv temp_file Input_file
in above code. Also in case your Input_file is TAB delimited and you want to have output as TAB delimited format then change awk
to awk 'BEGINFS="OFS="t"
keep from {for....
code as it is as mentioned above.
Explanation: Adding explanation for above code.
awk ' ##Starting awk program here.
##Startig conditions BLOCK here.
for(i=1;i<=NF;i++)imgr ##Closing BLOCK for for loop here.
print val ##Printing value of variable val here.
val="" ##Nullifying variable val value here.
##Closing main BLOCK now.
' Input_file ##Mentioning Input_file name here.
EDIT: Example of run of code.
awk 'for(i=1;i<=NF;i++)if($i ~ /^(updr;print val;val=""' Input_file
48358.00 1015.00 523
48562.00 1169.00 523
48305.00 1210.00 523
48285.00 1135.00 523
48459.00 1210.00 523
48246.00 881.00 523
48439.00 1109.00 523
1
$i ~ /^(updr|udrl|imgr|imgl)$/
?
– jhnc
Mar 7 at 11:15
@jhnc, thank you for letting me know the shortcut, changed solution now, thank you.
– RavinderSingh13
Mar 7 at 11:17
it's also a bugfix,/updr/
matchesasdasdsupdrwqwewe
. :-) For efficiency, you could also do,i++; val = ... $i; i++
– jhnc
Mar 7 at 11:19
@jhnc, thank you for letting know.
– RavinderSingh13
Mar 7 at 11:26
1
oops. secondi++
shouldn't be there. Idea is to skip the regexp check of the field after the current match (as we know that it can't)
– jhnc
Mar 7 at 11:29
|
show 8 more comments
Could you please try following(it will show the number next to strings whichever OP mentioned to search for).
awk 'for(i=1;i<=NF;i++)if($i ~ /^(updr;print val;val=""' Input_file
Or adding a non-one liner form of solution.
awk '
for(i=1;i<=NF;i++)
if($i ~ /^(updr
print val
val=""
' Input_file
In case you want to save output ito Input_fie itself append > temp_file && mv temp_file Input_file
in above code. Also in case your Input_file is TAB delimited and you want to have output as TAB delimited format then change awk
to awk 'BEGINFS="OFS="t"
keep from {for....
code as it is as mentioned above.
Explanation: Adding explanation for above code.
awk ' ##Starting awk program here.
##Startig conditions BLOCK here.
for(i=1;i<=NF;i++)imgr ##Closing BLOCK for for loop here.
print val ##Printing value of variable val here.
val="" ##Nullifying variable val value here.
##Closing main BLOCK now.
' Input_file ##Mentioning Input_file name here.
EDIT: Example of run of code.
awk 'for(i=1;i<=NF;i++)if($i ~ /^(updr;print val;val=""' Input_file
48358.00 1015.00 523
48562.00 1169.00 523
48305.00 1210.00 523
48285.00 1135.00 523
48459.00 1210.00 523
48246.00 881.00 523
48439.00 1109.00 523
Could you please try following(it will show the number next to strings whichever OP mentioned to search for).
awk 'for(i=1;i<=NF;i++)if($i ~ /^(updr;print val;val=""' Input_file
Or adding a non-one liner form of solution.
awk '
for(i=1;i<=NF;i++)
if($i ~ /^(updr
print val
val=""
' Input_file
In case you want to save output ito Input_fie itself append > temp_file && mv temp_file Input_file
in above code. Also in case your Input_file is TAB delimited and you want to have output as TAB delimited format then change awk
to awk 'BEGINFS="OFS="t"
keep from {for....
code as it is as mentioned above.
Explanation: Adding explanation for above code.
awk ' ##Starting awk program here.
##Startig conditions BLOCK here.
for(i=1;i<=NF;i++)imgr ##Closing BLOCK for for loop here.
print val ##Printing value of variable val here.
val="" ##Nullifying variable val value here.
##Closing main BLOCK now.
' Input_file ##Mentioning Input_file name here.
EDIT: Example of run of code.
awk 'for(i=1;i<=NF;i++)if($i ~ /^(updr;print val;val=""' Input_file
48358.00 1015.00 523
48562.00 1169.00 523
48305.00 1210.00 523
48285.00 1135.00 523
48459.00 1210.00 523
48246.00 881.00 523
48439.00 1109.00 523
edited Mar 8 at 10:41
answered Mar 7 at 10:53
RavinderSingh13RavinderSingh13
29.7k41639
29.7k41639
1
$i ~ /^(updr|udrl|imgr|imgl)$/
?
– jhnc
Mar 7 at 11:15
@jhnc, thank you for letting me know the shortcut, changed solution now, thank you.
– RavinderSingh13
Mar 7 at 11:17
it's also a bugfix,/updr/
matchesasdasdsupdrwqwewe
. :-) For efficiency, you could also do,i++; val = ... $i; i++
– jhnc
Mar 7 at 11:19
@jhnc, thank you for letting know.
– RavinderSingh13
Mar 7 at 11:26
1
oops. secondi++
shouldn't be there. Idea is to skip the regexp check of the field after the current match (as we know that it can't)
– jhnc
Mar 7 at 11:29
|
show 8 more comments
1
$i ~ /^(updr|udrl|imgr|imgl)$/
?
– jhnc
Mar 7 at 11:15
@jhnc, thank you for letting me know the shortcut, changed solution now, thank you.
– RavinderSingh13
Mar 7 at 11:17
it's also a bugfix,/updr/
matchesasdasdsupdrwqwewe
. :-) For efficiency, you could also do,i++; val = ... $i; i++
– jhnc
Mar 7 at 11:19
@jhnc, thank you for letting know.
– RavinderSingh13
Mar 7 at 11:26
1
oops. secondi++
shouldn't be there. Idea is to skip the regexp check of the field after the current match (as we know that it can't)
– jhnc
Mar 7 at 11:29
1
1
$i ~ /^(updr|udrl|imgr|imgl)$/
?– jhnc
Mar 7 at 11:15
$i ~ /^(updr|udrl|imgr|imgl)$/
?– jhnc
Mar 7 at 11:15
@jhnc, thank you for letting me know the shortcut, changed solution now, thank you.
– RavinderSingh13
Mar 7 at 11:17
@jhnc, thank you for letting me know the shortcut, changed solution now, thank you.
– RavinderSingh13
Mar 7 at 11:17
it's also a bugfix,
/updr/
matches asdasdsupdrwqwewe
. :-) For efficiency, you could also do, i++; val = ... $i; i++
– jhnc
Mar 7 at 11:19
it's also a bugfix,
/updr/
matches asdasdsupdrwqwewe
. :-) For efficiency, you could also do, i++; val = ... $i; i++
– jhnc
Mar 7 at 11:19
@jhnc, thank you for letting know.
– RavinderSingh13
Mar 7 at 11:26
@jhnc, thank you for letting know.
– RavinderSingh13
Mar 7 at 11:26
1
1
oops. second
i++
shouldn't be there. Idea is to skip the regexp check of the field after the current match (as we know that it can't)– jhnc
Mar 7 at 11:29
oops. second
i++
shouldn't be there. Idea is to skip the regexp check of the field after the current match (as we know that it can't)– jhnc
Mar 7 at 11:29
|
show 8 more comments
Using Perl one-liner
perl -ne ' while( /(updr|udrl|imgr|imgl)s+(S+)/g ) print "$2 " print "n" ' file
with your given inputs
$ cat vijaya.txt
updr 48358.00 updl 120 imgr 1015.00 imgl 523
updr 48562.00 updl 120 imgr 1169.00 imgl 523
updr 48305.00 updl 121 imgr 1210.00 imgl 523
updr 48285.00 updl 121 imgr 1135.00 imgl 523
updr 48459.00 updl 121 imgr 1210.00 imgl 523
updr 48246.00 updl 120 imgr 881.00 imgl 523
updr 48439.00 updl 120 imgr 1109.00 imgl 523
$ perl -ne ' while( /(updr|udrl|imgr|imgl)s+(S+)/g ) print "$2 " print "n" ' vijaya.txt
48358.00 1015.00 523
48562.00 1169.00 523
48305.00 1210.00 523
48285.00 1135.00 523
48459.00 1210.00 523
48246.00 881.00 523
48439.00 1109.00 523
$
I am looking a command using shell script ...Thanks for your solution in perl it may helpful to others too.
– vijaya m
Mar 11 at 4:50
@ please share a working command in shell script. Still i did not able to crack it.
– vijaya m
Mar 11 at 4:51
It is working with the same logic above only thing is output in the file is after so many lines not at the beginning of the file 49368.00 121 845.00 523 48542.00 121 1170.00 523 echoawk 'BEGIN print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
Thanks guys for your help here is the final command which i was looking to print o/p echoawk ' BEGIN OFS="," ;print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" /updr/ for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
add a comment |
Using Perl one-liner
perl -ne ' while( /(updr|udrl|imgr|imgl)s+(S+)/g ) print "$2 " print "n" ' file
with your given inputs
$ cat vijaya.txt
updr 48358.00 updl 120 imgr 1015.00 imgl 523
updr 48562.00 updl 120 imgr 1169.00 imgl 523
updr 48305.00 updl 121 imgr 1210.00 imgl 523
updr 48285.00 updl 121 imgr 1135.00 imgl 523
updr 48459.00 updl 121 imgr 1210.00 imgl 523
updr 48246.00 updl 120 imgr 881.00 imgl 523
updr 48439.00 updl 120 imgr 1109.00 imgl 523
$ perl -ne ' while( /(updr|udrl|imgr|imgl)s+(S+)/g ) print "$2 " print "n" ' vijaya.txt
48358.00 1015.00 523
48562.00 1169.00 523
48305.00 1210.00 523
48285.00 1135.00 523
48459.00 1210.00 523
48246.00 881.00 523
48439.00 1109.00 523
$
I am looking a command using shell script ...Thanks for your solution in perl it may helpful to others too.
– vijaya m
Mar 11 at 4:50
@ please share a working command in shell script. Still i did not able to crack it.
– vijaya m
Mar 11 at 4:51
It is working with the same logic above only thing is output in the file is after so many lines not at the beginning of the file 49368.00 121 845.00 523 48542.00 121 1170.00 523 echoawk 'BEGIN print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
Thanks guys for your help here is the final command which i was looking to print o/p echoawk ' BEGIN OFS="," ;print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" /updr/ for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
add a comment |
Using Perl one-liner
perl -ne ' while( /(updr|udrl|imgr|imgl)s+(S+)/g ) print "$2 " print "n" ' file
with your given inputs
$ cat vijaya.txt
updr 48358.00 updl 120 imgr 1015.00 imgl 523
updr 48562.00 updl 120 imgr 1169.00 imgl 523
updr 48305.00 updl 121 imgr 1210.00 imgl 523
updr 48285.00 updl 121 imgr 1135.00 imgl 523
updr 48459.00 updl 121 imgr 1210.00 imgl 523
updr 48246.00 updl 120 imgr 881.00 imgl 523
updr 48439.00 updl 120 imgr 1109.00 imgl 523
$ perl -ne ' while( /(updr|udrl|imgr|imgl)s+(S+)/g ) print "$2 " print "n" ' vijaya.txt
48358.00 1015.00 523
48562.00 1169.00 523
48305.00 1210.00 523
48285.00 1135.00 523
48459.00 1210.00 523
48246.00 881.00 523
48439.00 1109.00 523
$
Using Perl one-liner
perl -ne ' while( /(updr|udrl|imgr|imgl)s+(S+)/g ) print "$2 " print "n" ' file
with your given inputs
$ cat vijaya.txt
updr 48358.00 updl 120 imgr 1015.00 imgl 523
updr 48562.00 updl 120 imgr 1169.00 imgl 523
updr 48305.00 updl 121 imgr 1210.00 imgl 523
updr 48285.00 updl 121 imgr 1135.00 imgl 523
updr 48459.00 updl 121 imgr 1210.00 imgl 523
updr 48246.00 updl 120 imgr 881.00 imgl 523
updr 48439.00 updl 120 imgr 1109.00 imgl 523
$ perl -ne ' while( /(updr|udrl|imgr|imgl)s+(S+)/g ) print "$2 " print "n" ' vijaya.txt
48358.00 1015.00 523
48562.00 1169.00 523
48305.00 1210.00 523
48285.00 1135.00 523
48459.00 1210.00 523
48246.00 881.00 523
48439.00 1109.00 523
$
answered Mar 8 at 10:59
stack0114106stack0114106
4,2282421
4,2282421
I am looking a command using shell script ...Thanks for your solution in perl it may helpful to others too.
– vijaya m
Mar 11 at 4:50
@ please share a working command in shell script. Still i did not able to crack it.
– vijaya m
Mar 11 at 4:51
It is working with the same logic above only thing is output in the file is after so many lines not at the beginning of the file 49368.00 121 845.00 523 48542.00 121 1170.00 523 echoawk 'BEGIN print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
Thanks guys for your help here is the final command which i was looking to print o/p echoawk ' BEGIN OFS="," ;print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" /updr/ for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
add a comment |
I am looking a command using shell script ...Thanks for your solution in perl it may helpful to others too.
– vijaya m
Mar 11 at 4:50
@ please share a working command in shell script. Still i did not able to crack it.
– vijaya m
Mar 11 at 4:51
It is working with the same logic above only thing is output in the file is after so many lines not at the beginning of the file 49368.00 121 845.00 523 48542.00 121 1170.00 523 echoawk 'BEGIN print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
Thanks guys for your help here is the final command which i was looking to print o/p echoawk ' BEGIN OFS="," ;print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" /updr/ for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
I am looking a command using shell script ...Thanks for your solution in perl it may helpful to others too.
– vijaya m
Mar 11 at 4:50
I am looking a command using shell script ...Thanks for your solution in perl it may helpful to others too.
– vijaya m
Mar 11 at 4:50
@ please share a working command in shell script. Still i did not able to crack it.
– vijaya m
Mar 11 at 4:51
@ please share a working command in shell script. Still i did not able to crack it.
– vijaya m
Mar 11 at 4:51
It is working with the same logic above only thing is output in the file is after so many lines not at the beginning of the file 49368.00 121 845.00 523 48542.00 121 1170.00 523 echo
awk 'BEGIN print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
It is working with the same logic above only thing is output in the file is after so many lines not at the beginning of the file 49368.00 121 845.00 523 48542.00 121 1170.00 523 echo
awk 'BEGIN print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
Thanks guys for your help here is the final command which i was looking to print o/p echo
awk ' BEGIN OFS="," ;print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" /updr/ for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
Thanks guys for your help here is the final command which i was looking to print o/p echo
awk ' BEGIN OFS="," ;print "UpdateRate,UpdateLenght,ImgeRate,ImageLength" /updr/ for(i=1;i<=NF;i++)updl;print val;val=""' client_stat.txt > client_stat_onlyData.csv
– vijaya m
21 hours ago
add a comment |
vijaya m is a new contributor. Be nice, and check out our Code of Conduct.
vijaya m is a new contributor. Be nice, and check out our Code of Conduct.
vijaya m is a new contributor. Be nice, and check out our Code of Conduct.
vijaya m is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2fstackoverflow.com%2fquestions%2f55041969%2fhow-do-i-get-multiple-number-strings-after-brackets-using-sed-or-awk%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
A warm welcome to SO, special thanks for adding whatever you have tried and provding the samples of input and expected output. You almost posted a ideal post, only thing missed is CODE TAGS, please do wrap your samples with code tags using
button of your post(whch you did partially too, you need to cover al samples with it), keep learning and keep sharing on this GREAT site SO, cheers.
– RavinderSingh13
Mar 7 at 10:54