Tuesday, July 24, 2018

unix - Bash string explode




My file looks like this:




record=123
date=2012.01.20 10:22


In the bash file I do cat myfile.ini, and then I need to use something like explode, because I need ONLY to grep the 123 numeric record data, and nothing else.



How it can be done in the bash ?


Answer



awk -F'=| ' '/record/ {print $2}'



Substitute "date" for "record" in the command above to get the date (the time would be in $3).



This keys on the names of the variables rather than depending on a regex match of the value. It uses spaces or equal signs as field separators.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...