[Solved] Changing 0 to 1 and 1 to 0


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Changing 0 to 1 and 1 to 0
# 1  
Old 09-02-2012
[Solved] Changing 0 to 1 and 1 to 0

Hi

I have an expression that returns 1 if a text is found and 0 if its not found.
I need it the other way around. 0 of found and 1 if its not found

Code:
echo $((`cat /var/log/system1/output.html | grep aligment | head -n1 | wc -l`))

Is this possible without doing an if/then/else, just with math (bolean) in same line?

Edit
"grep -q" worked great

Last edited by Jotne; 09-02-2012 at 09:06 AM..
# 2  
Old 09-02-2012
Try this:
Code:
grep -q alignment /var/log/system1/output.html && echo 0 || echo 1

--
Bye
This User Gave Thanks to Lem For This Post:
# 3  
Old 09-02-2012
You got Useless Use of Cat AwardSmilie

With awk...

Code:
awk '/search_string/ {{s="0";next}}END{if(s) {print s}else{print "1"}}' file

This User Gave Thanks to pamu For This Post:
# 4  
Old 09-02-2012
Code:
grep -q alignment /var/log/system1/output.html; echo $?

# 5  
Old 09-02-2012
Quote:
Originally Posted by RudiC
Code:
grep -q alignment /var/log/system1/output.html; echo $?

Hi Rudic,

$? status is not always 0 or 1;

Please check here..

Regards,
pamuSmilie
# 6  
Old 09-02-2012
Thanks, pamu, you're absolutely right! If using bash, replace the echo $? by
Code:
 echo $(( $??1:0 ))

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

[Solved] Question changing timezone rules / zic

Dear, One of our customer which is located in Iraq/Baghdad, has informed us about a official change in daylight saving time in few days later and has asked us to fix this issue. So, the current timezone of that system is set as 'Asia/Baghdad' which is correct. however to fix the issue I went... (0 Replies)
Discussion started by: Anti_Evil
0 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Writing a loop to changing the names of files in a directory

Hi, I would like to write a loop to change the names of files in a directory. The files are called data1.txt through data1000.txt. I'd like to change their names to a1.txt through a1000.txt. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

3. Shell Programming and Scripting

[Solved] Need help changing a field from MM/DD/YY to DD/MM/YY format

Hi, I need help changing a field from MM/DD/YY to DD/MM/YY format. Suppose a file a.csv. The record is "11/16/09","ABC"," 1","EU","520892414","1","600","31351000","1234567","ANR BANK CO. LTD" "11/16/09","PQR"," 2","EU","520892427","1","600","31351000","5467897","ANR BANK CO.... (4 Replies)
Discussion started by: Gangadhar Reddy
4 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Help needed to have changing value to the command prompt string variable PS1

Hi, I am using git bash terminal window to do git operations. I have set the prompt string variable PS1 in the ~/.bashrc file as follows: export PS1=" " This is intended to show me the current git branch's name which is active as part of the prompt string. But, the problem is when I do a git... (2 Replies)
Discussion started by: royalibrahim
2 Replies

5. UNIX for Advanced & Expert Users

[SOLVED] LDAP Constraint Violation while changing password

Hello there, I hope that I am posting in the right section here, please advise if I posted wrong. I currently try to change passwords in our Active Directory Envoirenment via LDAP on Linux since the users in question do not have access to a windows-machine and we want to keep it that way. ... (0 Replies)
Discussion started by: henryford
0 Replies

6. Shell Programming and Scripting

[SOLVED] Changing file names

I have written a csh script that changes the name of file from src to dst. I am getting the error below: TESTAmvfiles DONE TESTAmvfiles set: Variable name must begin with a letter. The csh script is: #!/bin/csh #... (0 Replies)
Discussion started by: kristinu
0 Replies

7. Shell Programming and Scripting

[Solved] Changing to upper case in csh

How can I change a string contained in a variable to upper case using csh ??? ---------- Post updated at 08:39 AM ---------- Previous update was at 08:29 AM ---------- I think I've got it, using tr has solved the problem set opt = ` echo $opt | tr "" "" ` (1 Reply)
Discussion started by: kristinu
1 Replies

8. Shell Programming and Scripting

[solved] merging two files and writing to another file- solved

i have two files as file1: 1 2 3 file2: a b c and the output should be: file3: 1~a 2~b 3~c (1 Reply)
Discussion started by: mlpathir
1 Replies

9. UNIX for Dummies Questions & Answers

Changing / to - with vi

Hi just learning Unix in college now and this is my first post here, so I dunno if this goes here, or in the homework section technically. Anywho, trying to change all the / in a file into - using vi... i went into the command prompt, and put in :%s///-/g and it comes up with E488: Trailing... (2 Replies)
Discussion started by: SoVi3t
2 Replies

10. Shell Programming and Scripting

Changing userID and Changing group and GID

Hello, I want to write a ksh script about changing UID and changing group with GID. There are multiple servers i want to perform that job. linux1 linux2 linux3 linux4 linux5 ...... . . . . . 1.) How can i enter "password" in script rather asking me? I was trying this... ssh... (2 Replies)
Discussion started by: deal732
2 Replies
Login or Register to Ask a Question