File read format issue in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File read format issue in UNIX
# 1  
Old 07-29-2015
File read format issue in UNIX

hi all.

my loop is getting failed eventhoug it is 1=1 but it is failure message.
any help plz

Code:
Output expected :
[1 =1 ]

echo "sucesss"

Code:
code

out=`cat bit.txt`
if [[ $out = 1 ]];
then
echo "sucess"
else
echo "Failure"
log file :
+ + cat bit.txt
out=
                                             1
+ [[
                                             1                                   = 1 ]]
+ echo failire

Input file 

home/unix>cat bit.txt

                                             1

# 2  
Old 07-29-2015
The string consisting of 45 spaces followed by a "1" is not the same as the string "1". To get what you seem to want you could use any of the following:
  • Change out=`cat bit.txt` to read out < bit.txt and use the rest of your script as is.
  • Change [[ $out = 1 ]] to [[ out -eq 1 ]] (with either the cat or the read).
  • Change [[ $out = 1 ]] to [ $out = 1 ] (with either the cat or the read).
  • Change [[ $out = 1 ]] to [ $out -eq 1 ] (with either the cat or the read).
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 07-30-2015
Hi Don,

Thanks for your help.

It works now. Learned a new thing today Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read from file and replace in format

Hi Guys, I am having below content in a file which is tab dimited file.txt AUS AUS_UP NZ NZ_UP ENG ENG_AP I need to read the file content and replace it with below output format one to one replace try("AUS ").ss("AUS_UP") try("NZ ").ss("NZ_UP") try("ENG ").ss("ENG_AP") (3 Replies)
Discussion started by: rohit_shinez
3 Replies

2. UNIX for Beginners Questions & Answers

Issue with emailing format from UNIX

Need help as to why when I try email the following it does not come out right: DateOt=`date +"%a %b %d %T %Y"` TimeOt=`date +%H:%M:%S` interval=`cat $SecDiff| awk '{print $3}'` PortInReq2=`cat /shared/ftpdir/tools/quelog/logs/quelog.NPS_TO_SMG.log | grep PQI | wc -l` PortInRes2=`cat... (2 Replies)
Discussion started by: mrn6430
2 Replies

3. Shell Programming and Scripting

UNIX mail Format issue : Outlook 2007 and 2013

Hi, I prepare one backup report which drop mail with backup report. Same report looks different in outlook 2013. e.g : In outlook 2013 ( its a dummy example only ) : Server Instance Database Backup Time Status ------------------- --------- --------- -------------- ----------------------... (5 Replies)
Discussion started by: niteshtheone
5 Replies

4. Shell Programming and Scripting

File format issue

Hi All, In unix is there any command to format the file in exact order.I have a file which there is no order in the fileds, I need to order it. Its a dat file wrong format TDEAIG36533827CB1210004241 EUR20130610BL1300351 refers to CB|CCI|A|A|C|R|T 246.76 ... (1 Reply)
Discussion started by: nag_sathi
1 Replies

5. Shell Programming and Scripting

Read from text file;format and print output

Hi Following is the assumed input... Symmetrix ID : 12345 Originator Port wwn : 123456789 User-generated Name : 123456789/123456789 Sym Dev Dir:P LUN ------ ----- ----------------------- ---- --- ---- ---- ---- ------- 1234 ... (4 Replies)
Discussion started by: maddy.san
4 Replies

6. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

7. Shell Programming and Scripting

Read a file and put it in HTML format

Hi, I have one file as follows and I need to read this file contents in an HTML format. And send html file to some mail ids using sendmail. Communications Pvt Ltd Report AccountId Name Code IdBill Balance ... (3 Replies)
Discussion started by: Kattoor
3 Replies

8. Shell Programming and Scripting

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (2 Replies)
Discussion started by: Samtel
2 Replies

9. UNIX for Dummies Questions & Answers

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (1 Reply)
Discussion started by: Samtel
1 Replies

10. UNIX for Dummies Questions & Answers

File Format issue: Output of sqlplus

Hi, I am using a query like below in my shell script : { { echo "set echo off" echo "set head off" echo "whenever sqlerror exit -1; select NUMBER ||','|| FNAME ||','|| LOC ||','|| ... (2 Replies)
Discussion started by: deepakgang
2 Replies
Login or Register to Ask a Question