The following log files are available:
aaa1234.234;
bbbb5678.345;
ccc12345.356;
aaa2345.344;
bbbb6789.354;
ccc23456.678;
I want to extract only the number of bbbb from "bbb" to ";" from this file.
There is no string like bbb.
The number of digits in this number is indefinite, and it is also uncertain how many sets of data such as a-c, but
If possible, could you store it in different variables or in one variable, including line breaks?
This is a supplement
ans=`grep-o`bbbb[^;]*`test.txt`
was able to get out of bbbb;
In addition, sed replaces bbbb,
ans=`echo "$ans" | sed-e's /^bbb//'`
was able to extract lines with new lines.
I'd like to put this in a different variable for each line.
If I don't know the number of lines, it will be difficult to separate them.
Supplement 2
It worked by specifying a new line in IFS.
Thank you.
I have received a few answers, and I will summarize them now that they have been resolved.
ans=`awk-F'[;]'$1=="bbb"{print$2}'test.txt`
Or
ans=`grep-o`bbbb[^;]*`test.txt`
an = `echo "$ans" | sed-e's /^bbb//'`
allowed the variable ans to leave only between bbbb 」 and ;; 」 with a new line.
Next,
IFS='
'
for i in $ans;do
echo$i
done
I could treat it as a different variable by describing the function in echo.
Thank you to everyone who responded.
581 PHP ssh2_scp_send fails to send files as intended
911 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.