linux - Search a string in a file, then print the lines that start with that string -
i have assignment , have no thought when comes managing files, reading , writing. here's main problem:
i have script manages address book, @ moment menu finished, functions beingness used don't know how search or write file.
the first "option" gives user alternative (duh!) search address book contact name. pattern want utilize along lines of "name:address:email:phone", letting user set spaces in name, address not email nor phone, , numbers in lastly one. believe accomplish regular expressions, understand bit java lessons.
how can this, then? know grep
may useful, don' know of parameters after reading man pages. parsing line line done for line in $(file)
still not sure.
if you're allowed utilize grep
, may utilize awk
, , that's prefer parts of assignment.
looking contact name:
awk -v name="anton kovalenko" -f: '$1==name' "$file"
linux bash
No comments:
Post a Comment