I have a Linux machine with BusyBox,
which has a directory called /data/var/lib/connman
.
That directory holds some directories that I'm not interested in.
But it contains many .config files that have a file name pattern
like "wifi_<HASH1>_<HASH2>_managed_psk.config
".
The file name in my example contains the interesting hash part,
<HASH1>_<HASH2>
, which are alphanumeric characters.
Examples of the full file names are:
- "wifi_ff001122334_567890123456_managed_psk.config"
- "wifi_778899ad_112233445566_managed_none.config"
Then each file is a text file and if it contains a line I'm interested in:
Name = <SSID>
The interesting part is <SSID>
.
Real examples of that line are:
Name = MySSID
Name = r23$f"§F §"fsdfSdf
Now I want to get all the hashes from the file names together with their value of <SSID>, like this:
<HASH> : <SSID>
That's my desired output:
MySSID : 01abcd89
MyOtherSSID : ff001122334455,
r23öf"§F§"fsdfSdf : 7876543ad
So we need to grab the hash part from the file name and at the same time look at the file's content that comes after "Name =".
I've played around with a combination of grep and awk but never got the desired output.
What command can I use to achieve that?
<SSID> : <HASH>
. 2) are the Real Examples of<SSID>
sample data from two different files, or both in one file? 3) if you're not going to use the<HASH2>
from the file name, you can simplify your problem description by removing that info. (replace in filehame with_otherstuff
?)` 4) Theawk
programing language is one tool that you can consider using. See Awk Tutorial and note theFILENAME
variable as well as$1, $2, $3, .... $NF
etc. ...