1 | initial version |
Here's an example of how to use grep and awk to filter alphanumeric lines from a file and print them as a Python array:
grep -E '^[a-zA-Z0-9]+$' file.txt | awk '{printf("\"%s\", ", $0)}' | sed 's/, $/\n/' | awk '{printf("[%s]", $0)}'
This command uses grep to filter the alphanumeric lines from file.txt by searching for lines that match the regular expression ^[a-zA-Z0-9]+$
. The output of grep is then piped to the first awk command, which adds double quotes around each line to make it a valid string in Python. The output of this command is then piped to the second awk command, which uses printf to print the lines as a Python array in the format [ "line1", "line2", ... ]
.