LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 03-04-2010, 04:06 AM   #1
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Rep: Reputation: 16
i need to output a text file in proper format


this is what my shell script does .. it compares two files using md5... if they are same , a corresponding character is output to a text file .. but the problem is it gets appended by default.. is there any way to output in a normal way because the text is a message and it should be of proper format
here is my script
Code:
#!/bin/bash
g=`tail -1 new.txt|head -n 1`


array=( a b c d e f g h i j k l m n o p q r s t u v w x y z )

for((i=1 ; i <$g+1 ; i++))
 do
   for ((j=0; j < 26 ; j++))  
    do
    
    a=`md5sum data$i | cut -f1 -d' '`
    b=`md5sum data${array[$j]} | cut -f1 -d' '`
   
    if [[ "$a" = "$b" ]]
    then
    echo "${array[$j]}" >> originalmessage.txt
    
    fi

    done
done
the output text file is like this
h
e
l
l
o


the message is supposed to be hello , i need to get rid of the endlines somehow.. can anyone help me please???
 
Old 03-04-2010, 04:13 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
From the man page for echo:
Code:
DESCRIPTION
       Echo the STRING(s) to standard output.

       -n     do not output the trailing newline
If you need to compare only two files, why do you need the arrays and use md5 at all?
cmp $file1 $file2 && do something || do something else

Last edited by jschiwal; 03-04-2010 at 04:15 AM.
 
1 members found this post helpful.
Old 03-04-2010, 04:14 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Add the -n option to the echo line. I.e: echo -n "${array[$j]}" >> originalmessage.txt

And, depending on your needs, print/echo a newline when done with the second loop.


Too late

Last edited by druuna; 03-04-2010 at 04:15 AM. Reason: jschiwal was faster....
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting colored text output file using C ibabhelix Programming 2 11-04-2009 03:53 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 03:36 PM
how to format a text file to automate testing procedure Ashok_mittal Linux - Newbie 1 03-17-2008 09:39 AM
in Pascal: how to exec a program, discard text output or send to text file Valkyrie_of_valhalla Programming 6 05-02-2007 10:50 AM
Linux - ASCI - Windows, proper file format issue aaronluke Linux - General 1 11-07-2002 11:47 PM


All times are GMT -5. The time now is 04:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration