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










1















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









share|improve this question









New contributor




vijaya m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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
















1















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









share|improve this question









New contributor




vijaya m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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














1












1








1








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









share|improve this question









New contributor




vijaya m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question









New contributor




vijaya m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




vijaya m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Mar 7 at 10:55









RavinderSingh13

29.7k41639




29.7k41639






New contributor




vijaya m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Mar 7 at 10:48









vijaya mvijaya m

61




61




New contributor




vijaya m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





vijaya m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






vijaya m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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

















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













2 Answers
2






active

oldest

votes


















0














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





share|improve this answer




















  • 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/ 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






  • 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



















0














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

$





share|improve this answer























  • 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 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











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.









draft saved

draft discarded


















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









0














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





share|improve this answer




















  • 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/ 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






  • 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
















0














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





share|improve this answer




















  • 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/ 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






  • 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














0












0








0







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





share|improve this answer















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






share|improve this answer














share|improve this answer



share|improve this answer








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/ 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






  • 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













  • 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/ 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






  • 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








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














0














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

$





share|improve this answer























  • 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 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
















0














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

$





share|improve this answer























  • 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 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














0












0








0







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

$





share|improve this answer













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

$






share|improve this answer












share|improve this answer



share|improve this answer










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 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


















  • 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 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

















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











vijaya m is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme