• Post Reply Bookmark Topic Watch Topic
  • New Topic

Assigning output of grep to variable  RSS feed

 
Fred Victa
Ranch Hand
Posts: 206
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I assign the output of the following grep statements to different variables?

grep -i '550|552|553' ftp.log

grep -i 'No such file' ftp.log
 
Tim Cooke
Marshal
Posts: 4044
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You say 'variables'. What language are we talking here?
 
Fred Victa
Ranch Hand
Posts: 206
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:You say 'variables'. What language are we talking here?


This is for a UNIX shell script.
 
Tim Cooke
Marshal
Posts: 4044
239
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could have easily found this with a quick search on the internet.

But here goes anyway:

I have a file called 'somefile':

and a Shell script called 'do-grep.sh':
(Note: Those are backticks, not single quotes.)

Results in:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!