The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
A program to trace execution of another program jiten_hegde High Level Programming 3 08-19-2008 06:26 AM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan UNIX for Dummies Questions & Answers 3 08-02-2008 06:21 PM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan High Level Programming 1 04-30-2008 02:44 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 08-24-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Good c++ Program

Hi Guru's
I wrote a shell script some days back.
i want to translate this script to a c++ program.I need help from you guys.I have never done any programming in c++ til now.


Code:
#!/usr/bin/ksh

inpFile=$1
outFile="$HOME/Output.txt"
errFile="$HOME/Error.txt"
dupFile="$HOME/Duplicate.txt"
tmpFile1=sample1.txt
tmpFile2=sample2.txt
sortFile=sortfile.txt

TOTAL_FILEDS=9
COUNT=1
PRINT_FLAG=0
LINE_NO=1
check_lines=0
rm -f $outFile $errFile $dupFile
sort $inpFile | uniq -d > $dupFile
#sort $inpFile | uniq -d | sed "s/$/& : Duplicate/g" >> $errFile
for line in $(cat $inpFile)
do
  	count_fields=$(echo $line | sed "s/00,*//g;s/,$//g" | wc -c)
	echo "count_fields is: $count_fields"
	cnt_flds1=$(echo $line | cut -d',' -f1-9 | sed "s/00,*//g;s/,$//g" | wc -c )
	echo "cnt_flds1 is : $cnt_flds1"
	cnt_flds2=$(echo $line | cut -d',' -f10-18 | sed "s/00,*//g;s/,$//g" | wc -c )
	echo "cnt_flds2 is : $cnt_flds2"
	cnt_flds3=$(echo $line | cut -d',' -f19-27 | sed "s/00,*//g;s/,$//g" | wc -c )
	echo "cnt_flds3 is : $cnt_flds3"
	if [[ $count_fields -eq 45 && $cnt_flds1 -eq 15 && $cnt_flds2 -eq 15 && $cnt_flds3 -eq 15 ]]
	then
            	PRINT_FLAG=0

		echo $line | cut -d',' -f1-9 > $sortFile
		echo $line | cut -d',' -f10-18 >> $sortFile
		echo $line | cut -d',' -f19-27 >> $sortFile

		while [[ $COUNT -le $TOTAL_FILEDS ]]
		do
                  	cut -d',' -f$COUNT $sortFile | grep -v 00 > $tmpFile1
			cut -d',' -f$COUNT $sortFile | grep -v 00 | sort > $tmpFile2

			diff $tmpFile1 $tmpFile2 > /dev/null
			if [[ $? -eq 1 || ! -s $tmpFile1 ]]
			then
                            	PRINT_FLAG=1
				break
fi
		COUNT=$((COUNT+1))
		done
		echo "Value of print flag is : $PRINT_FLAG"
		if [[ $PRINT_FLAG -eq 0 ]]
		then
			echo "$line : SUCCESS" >> $outFile
		else
			echo "$line : ERROR in $COUNT" >> $errFile
		fi
	else
		echo "$line : Out of Scope"  >> $errFile
	fi
	COUNT=1
	check_lines=$((check_lines+count_fields))
	if [[ $LINE_NO -eq 6 ]]
	then
		LINE_NO=0
		if [[ $check_lines -eq 270 ]]
		then
			echo " **** Success A Strip has 90 digits"
		else
			echo "----- Error,Check the above -----"
		fi
		check_lines=0
	fi
	LINE_NO=$((LINE_NO+1))
done
rm -f $tmpFile1 $tmpFile2 $sortFile
exit 0

The input file is----

Code:
00,11,21,00,00,55,00,73,83,07,00,22,39,43,00,66,00,00,00,15,00,00,44,58,67,00,87
02,14,24,30,00,00,00,70,00,00,00,00,32,47,50,60,74,00,04,16,27,38,00,00,00,00,89
00,00,00,00,42,52,61,71,86,01,00,29,33,00,59,00,75,00,03,19,00,00,45,00,68,00,88
00,13,20,31,00,00,64,76,00,05,00,00,35,41,56,00,00,81,00,00,28,00,00,57,65,79,90
06,10,00,36,40,00,00,00,80,00,12,25,00,00,51,62,72,00,09,00,00,37,49,00,69,00,84
00,17,23,00,46,53,00,77,00,08,00,00,34,00,54,00,78,82,00,18,26,00,48,00,63,00,85
00,14,23,39,00,00,60,00,87,02,00,28,00,41,50,00,75,00,03,15,00,00,44,00,68,00,90
00,16,25,35,00,53,00,71,00,08,00,00,36,40,00,62,00,88,00,00,27,37,00,58,64,78,00
05,10,00,00,48,52,00,73,00,00,00,24,31,00,57,66,00,81,07,17,00,00,49,00,00,79,85
00,00,20,33,00,00,63,70,80,06,12,00,34,42,56,00,00,00,00,00,29,00,00,59,69,74,86
04,13,00,32,43,00,65,00,00,00,18,22,00,00,55,00,72,84,09,00,00,38,47,00,67,00,89
01,11,21,00,00,51,00,76,00,00,00,26,30,45,54,00,00,82,00,19,00,00,46,00,61,77,83

Thanks

Last edited by vino; 08-24-2007 at 09:48 AM.. Reason: Added code tags.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0