Yes, you can do that. Your command would be:
cat /boot/config-3.19.0-32-generic | grep CONFIG_ARCH_DEFCONFIG | awk -F'"' '{print $2}'
which would return only:
arch/x86/configs/x86_64_defconfig
The awk
command uses field separators with the -F
command, and to set it to use double-quotes, you type it in with single-quotes around it like -F'"'
. Then the '{print $2}'
tells awk to print the second set after the field separator.
Hope this helps!
New version
The script you posted indeed groups the emails by domain, with no limit in number. Below a version that will group emails by domain, but split the found list into arbitrary chunks. Each chunk will be printed into a line, starting with the corresponding domain.
The script
#!/usr/bin/env python3
from operator import itemgetter
from itertools import groupby, islice
import os
import sys
dr = sys.argv[1]
size = 3
def chunk(it, size):
it = iter(it); return iter(lambda: tuple(islice(it, size)), ())
for f in os.listdir(dr):
# list the files
with open(os.path.join(dr, "chunked_"+f), "wt") as report:
file = os.path.join(dr, f)
# create a list of email addresses and domains, sort by domain
lines = [[l.strip(), l.split("@")[-1].strip()] for l in open(file).readlines()]
lines.sort(key=itemgetter(1))
# group by domain, split into chunks
for domain, occurrence in groupby(lines, itemgetter(1)):
adr = list(chunk([s[0] for s in occurrence], size))
# write lines to output file
for a in adr:
report.write(domain+","+",".join(a)+"\n")
To use
- Copy the script into an empty file, save it as
chunked_list.py
In the head section, set the chunk size:
size = 5
Run the script with the directory as argument:
python3 /path/to/chunked_list.py /path/to/files
It wil then create an edited file of each of the files, named chunked_filename
, with the (chunked) grouped emails.
What it does
The script takes as input a directory with files like:
email1@domain1
email2@domain1
email3@domain2
email4@domain1
email5@domain1
email6@domain2
email7@domain1
email8@domain2
email9@domain1
email10@domain2
email11@domain1
Of each file, it creates a copy, like:
domain1,email1@domain1,email2@domain1,email4@domain1
domain1,email5@domain1,email7@domain1,email9@domain1
domain1,email11@domain1
domain2,email3@domain2,email6@domain2,email8@domain2
domain2,email10@domain2
(set cunksize = 3)
Best Answer
You can remove all occurrences of characters from a given set with
tr -d
. To remove the newline character use:As always you can use input and output redirection and pipes to read from or write to files and other processes.
If you want to keep the last newline you can simply add it back with
echo
orprintf '\n'
, e. g.: