If a.txt contains AA and BB with one-line to get


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If a.txt contains AA and BB with one-line to get
# 1  
Old 01-23-2013
If a.txt contains AA and BB with one-line to get

Code:
if xxxx;then 
echo "it pass"
fi

xxxx I want to use one line to get when a.txt contains AA and BB, it pass
# 2  
Old 01-23-2013
Do you means AA and BB on the same line? Try:
Code:
if grep -qE 'AA.*BB|BB.*AA' a.txt; then

# 3  
Old 01-23-2013
Quote:
Originally Posted by Scrutinizer
Do you means AA and BB on the same line? Try:
Code:
if grep -qE 'AA.*BB|BB.*AA' a.txt; then

No, your aa and bb in one line, I don't need it's in one line, if a.txt contains both then pass
# 4  
Old 01-23-2013
Try:
Code:
if grep -q "AA" a.txt && grep -q "BB" a.txt
then

# 5  
Old 01-23-2013
Code:
if [ $( awk 'BEGIN{c=0}/AA/&&/BB/{++c}END{print c}' a.txt ) -ne 0 ]
then
   echo "it pass"
fi

# 6  
Old 01-23-2013
@bipinajith: that would only work if AA and BB are on the same line
# 7  
Old 01-23-2013
Quote:
Originally Posted by Scrutinizer
@bipinajith: that would only work if AA and BB are on the same line
I'm sorry, I thought that is what the user want!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash incert line from 1.txt to 2.txt

i would like to insert a line from 2.txt into 1.txt between " and " or a way of adding to the end of each line " _01_ and have the numbers correspond to the line # 1.txt= foofoo "" _01_ foofoo "" _02_ foofoo "" _03_ foofoo "" _04_ 2.txt= ... (6 Replies)
Discussion started by: klein
6 Replies

2. Shell Programming and Scripting

Switch line in txt file

Hi I have problem with replace line in txt file , I have this string: 144185 DISK Piece qqr8ot6l_1_1 -- 144186 DISK Piece ukr8pf2e_1_1 -- 144187 DISK Piece ter8p9gc_1_1 -- 144188 DISK Piece 4er8qb84_1_1 and (8 Replies)
Discussion started by: primo102
8 Replies

3. UNIX for Dummies Questions & Answers

Split Every Line In Txt Into Separate Txt File, Named Same As The Line

Hi All Is there a way to export every line into new txt file where by the title of each txt output are same as the line ? I have this txt files containing names: Kandra Vanhooser Rhona Menefee Reynaldo Hutt Houston Rafferty Charmaine Lord Albertine Poucher Juana Maes Mitch Lobel... (2 Replies)
Discussion started by: Nexeu
2 Replies

4. UNIX for Dummies Questions & Answers

Script to delete files line by line in .txt document

Friends, I am in need to delete files from a directory on a regular basis. I want to place all the files to be deleted in delete .txt file and require a script to delete files, line by line from this delete.txt file. Please help me with this script as am new to unix scripting. (3 Replies)
Discussion started by: fop4658
3 Replies

5. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

6. Shell Programming and Scripting

Changing Line in Txt File

So I have a python program that I run, which runs accordingly to options I have listed in a text file (ie user_prefs). Now there are many options listed in this user_prefs.txt, but the one of most interest to me is that of the file path of the time series. I have over a hundred of these time... (8 Replies)
Discussion started by: Jimmyd24
8 Replies

7. Shell Programming and Scripting

Count per line in txt file

In a txt file called, eso.txt, I have: ...... 3 where process_status_flag = 70 and LISTENER_ID in (930.00, 931.00, 932.00, 933.00, 934.00) 4 group by LISTENER_ID 5 order by LISTENER_ID; LISTENER COUNT ----------... (3 Replies)
Discussion started by: Daniel Gate
3 Replies

8. Shell Programming and Scripting

Create different txt files per line

Hi All, I have a text file1.txt which looks like a9 a3 a4 ... and i want to create a seperate .txt files per each line. For example, output1.txt will have only one element "a9" output2.txt will have only one element "a3" ... Thanks, (1 Reply)
Discussion started by: senayasma
1 Replies

9. Shell Programming and Scripting

i need to read the last line in a txt file

i'm a beginner in shell and i have a txt file that is updating every second or msec so i need a program to read the last line of this txt file is this possible to do? (5 Replies)
Discussion started by: _-_shadow_-_
5 Replies

10. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies
Login or Register to Ask a Question