2
I have the following fictional file:
Location: Estado Title: Bahia Location: Estado Title: Pernanbuco Location: Estado Title: Alagoas Location: Cidade Title: Recife Location: Cidade Title: Barretos Location: Estado Title: Roraima Location: Estado Title: Tocatins
I need to filter both lines at the same time, and resume only the second referring to the first 'Location: [...]'
I tried some commands, however, I will post here only one! I believe to be the cleanest for understanding who reads.
cat info.txt | grep Cidade | awk 'NF' | awk '/Title:/{print $1}'
In this command above, I am searching for the titles of the location(s) that are the 'cities'. Note that in the file there are only two cities, and should return me the 'Title: [...]' of these respective cities.
The exit should be, but I’m not getting.. This one here:
Cidade Recife Barretos
That’s all right, I hope you understand.
Grateful for the well explained answer. The primordial factor was only the parameter
-A 1
of commandgrep
in which case I needed to know. So, replace the secondgrep Title
of his reply byawk -F "Title:" '{print $2}'
. Now, it’s like this:cat info.txt | grep Cidade -A 1 | awk -F "Title:" '{print $2}'
, just to be friendly to me remember.– Diego Henrique