Posts

Showing posts with the label grep

Reformat data using awk

Reformat data using awk I have a dataset that contains rows of UUIDs followed by locations and transaction IDs. The UUIDs are separated by a semi-colon (';') and the transactions are separated by tabs, like the following: 01234;LOC_1=ABC LOC_1=BCD LOC_2=CDE 56789;LOC_2=DEF LOC_3=EFG I know all of the location codes in advance. What I want to do is transform this data into a format I can load into SQL/Postgres for analysis, like this: 01234;LOC_1=ABC 01234;LOC_1=BCD 01234;LOC_2=CDE 56789;LOC_2=DEF 56789;LOC_3=EFG I'm pretty sure I can do this easily using awk (or similar) by looking up location IDs from a file (ex. LOC_1) and matching any instance of the location ID and printing that out next to the UUID. I haven't been able to get it right yet, and any help is much appreciated! My locations file is named location and my dataset is data . Note that I can edit the original file or write the results to a new file, either is fine. location data ...

Shell command to list file names where the matching is found

Shell command to list file names where the matching is found I am trying to search through a list of binary files to find some keywords on Mac. The following works to list out all the matches, but it doesn't show me the list of files where it is being found: find . -type f -exec strings {} ;|grep "Bv9qtsZRgspQliITY4" Is there any trick to do this? Do you still want to print the matches, or just the files’ names/paths? – Biffen Jun 29 at 10:07 5 Answers 5 Using -exec with a wee ‘script’: -exec find . -type f -exec sh -c 'strings "$1" | grep -q "Bv9qtsZRgspQliITY4"' -- {} ; -print The above will print the paths of all the matching files. If you also want to print the matches you can use: find . -typ...