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

madhar chod unix ke 10 commands dhang se likh nahi sakta hai

0 Answers   Cap Gemini,


Write a script to print the first 10 elements of fibonacci series.

0 Answers  


What is batch file programming?

0 Answers  


c program which accept one argument as a directory name and prints all the file name along with its inode number and total count of the file in directory

1 Answers  


Write a shell script to get current date, time, user name and current working directory.

0 Answers  






What are the four fundamental components of every file system on linux?

0 Answers  


What is scripting used for?

0 Answers  


What are the disadvantages of shell scripting?

0 Answers  


Rewrite the command to print the sentence and convert the variable to plural: echo “i like $variable”.

0 Answers  


What is the best shell scripting language?

0 Answers  


Is it possible to substitute "ls" command in the place of "echo" command?

0 Answers  


How to create environment variables?What are the conditions for creating variables?

1 Answers   Infosys, Wipro,


Categories