1

I need to write a shell program that installs some packages. The program will run on Linux (obviously some commands will not work, for example, on Arch-based distros).

So, I've got this file called config.conf with the following structure:

#EMAIL
email address here
#TWITTER
twitter account
#FORUM
a bunch of 'http://foru.ms'
#FACEBOOK

#REDDIT
reddit username

The program initial_install.sh should search for the lines that starts with an hash and, if the subsequent line is not empty, install the package needed for that category. For example, it searches for #TWITTER and, only if a twitter account is written just below that line, it installs the rainbowstream twitter client with sudo apt-get install rainbowstream.

Can you help me? I have no ideas, i'm not really a 'shell expert'..

1

You can do it with grep

  cat filename | grep -A1 TWITTER | grep -v TWITTER

or, perhaps better, you can do it with awk

  awk '/TWITTER/{getline; print}' filename
1
  • uhm, understood what 'cat' will do: it seems it prints the line next to the one with the given word. But 1) i don't want to show THAT output (maybe --silent can solve it?) and i need something like 'if the line printed is not empty, do $this'...ideas? – d33pcode Nov 15 '14 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.