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
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 |
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 |
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 |
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 |
What is meant by $1 in shell script?
How to rename all the files in a folder having specific extension? Example: I have some files with extension (.txt) in a folder name 'Test'. I have to rename all the .txt files in a test and its subdirectories to .my extension.
i have 2 tables 4 colums table 1 respective values a1 6, a2 8,a3 9,a4 14 & table 2 respective values a1 6, a2 8, a3 9, a4 12. if compare 2 tables 3 colums values same then 4th column values 1)Qes diff >5 then (5 * diff value ) 2)Qes diff <5 the 5 3)Qes diff 5 then 5 print respective values..
There are three departments A,B and C.Write a query to display the names of all the persons( in departments other than A) who are paid higher than the person receiving the lowest salary in DEPT A
How to print pid of the current shell?
How to handle the delimiter unit seperator in Unix
What are the default permissions of a file when it is created?
Write a command sequence to find all the files modified in less than 2 days and print the record count of each.
How do I run a shell script on a mac?
write a shell script to generate a alert ? like when ur birthday came then generate a alert ur birthday is today like that ?
What are filters explain sort with all the options available?
what is this line in the shell script do ?#!/bin/ksh