Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-04-2010, 03:06 AM   #1
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
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++))
   for ((j=0; j < 26 ; j++))  
    a=`md5sum data$i | cut -f1 -d' '`
    b=`md5sum data${array[$j]} | cut -f1 -d' '`
    if [[ "$a" = "$b" ]]
    echo "${array[$j]}" >> originalmessage.txt

the output text file is like this

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, 03:13 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
From the man page for echo:
       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 03:15 AM.
1 members found this post helpful.
Old 03-04-2010, 03:14 AM   #3
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392

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 03:15 AM. Reason: jschiwal was faster....
1 members found this post helpful.


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 02: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 02:36 PM
how to format a text file to automate testing procedure Ashok_mittal Linux - Newbie 1 03-17-2008 08: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 09:50 AM
Linux - ASCI - Windows, proper file format issue aaronluke Linux - General 1 11-07-2002 10:47 PM > Forums > Linux Forums > Linux - Newbie

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

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