how to separate the even and odd number generated from one
file to two separate file i.e. even numbers in file1.txt and
odd numbers in file2.txt

Answers were Sorted based on User's Feedback



how to separate the even and odd number generated from one file to two separate file i.e. even numb..

Answer / roshini

echo enter filename
read file
for n in `cat $file`
do
i=`expr $n % 2`
if [ $i -eq 0 ]
then
echo $n>>even.txt
else
echo $n>>odd.txt
fi
done

Is This Answer Correct ?    19 Yes 4 No

how to separate the even and odd number generated from one file to two separate file i.e. even numb..

Answer / jaya prasad

echo "Enter the file name"
read file
awk '$NF % 2 == 0' $file > file1.txt
awk '$NF % 2 != 0' $file > file2.txt

Is This Answer Correct ?    9 Yes 1 No

how to separate the even and odd number generated from one file to two separate file i.e. even numb..

Answer / ganeswar bojanapu

#!/bin/bash
echo "Enter a file name"
read file
sed -n '1~2'p $file > oddlines.txt; (or) '1~2p'
sed -n '2~2'p $file > evenlines.txt (or) '2~2p'

Is This Answer Correct ?    0 Yes 0 No

how to separate the even and odd number generated from one file to two separate file i.e. even numb..

Answer / rahul

Can someon just use only one line script if we already knew the file name

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Shell Script Interview Questions

write a shell script to generate a alert ? like when ur birthday came then generate a alert ur birthday is today like that ?

0 Answers   Wells Fargo,


What language is shell scripting?

0 Answers  


Set up a Sev 2 alert when the Primary WA service fails. A windows batch script needs to be created that will monitor the WA service on the Primary and when the service stops/fails a Sev 2 TT is generated for a particular team ?

0 Answers   TCS,


What is the difference between grep and egrep?

0 Answers  


Explain how you Automate your application using Shell scripting.

0 Answers   MAHINDRA,






how is the oppurtunities for unix in the software

1 Answers  


Why do we write bin bash in shell scripts?

0 Answers  


How to include comments in your shell scripts?

3 Answers  


What does echo $0 do?

0 Answers  


There is a record with fields namely name,roll no.,salary,grade etc.Now,write a script to create a file with multiple records have same combination of fields but with unique roll numbers.The script should work for different names in the input file.

1 Answers   Wipro,


give me some website where i can get unix and testing meterials

1 Answers  


Explore about environment variables?

0 Answers  


Categories