alwbtc
alwbtc

Reputation: 29465

How to find lines containing two strings together in Linux?

I want to display lines that contain "addUser" and "2012-08-03" strings together on the same line in a Linux file. How to do this?

Upvotes: 1

Views: 2429

Answers (3)

Leonid Volnitsky
Leonid Volnitsky

Reputation: 9144

grep addUser filename | grep "<user>2012-08-03</user>" 

Upvotes: 1

InternetSeriousBusiness
InternetSeriousBusiness

Reputation: 2635

awk '/addUser/ && /2012-08-03/' < file

or

grep addUser < file | grep 2012-08-03

or

sed -n 's@addUser@&@p' < file | sed -n 's@2012-08-03@&@p'

or

ruby -e 'File.readlines( "file" ).each {|l| puts l if l =~ /addUser/ and l =~ /2012-08-03/ }'

Upvotes: 2

sunmoon
sunmoon

Reputation: 31

command in linux

echo "adduser 2012-08-03 " > data.txt

to see the contents of data.txt file type cat data.txt

or vi data.txt

Upvotes: 1

Related Questions