Shell scripts are very handful in reading or writing data to/from files.
The below shell script will take input file, which contains numbers in a column and output two files, containing these numbers in following order.
Example:
input.txt
11
22
33
44
55
66
output:
output1.txt output2.txt
11 22
33 44
55 66
Here is the script file: script1.sh
The below shell script will take input file, which contains numbers in a column and output two files, containing these numbers in following order.
Example:
input.txt
11
22
33
44
55
66
output:
output1.txt output2.txt
11 22
33 44
55 66
Here is the script file: script1.sh
- #!/bin/bash
- FILENAME=$1
- count=0
- while read LINE
- do
- let count++
- if [ "$count" -eq 1 ]; then
- echo $LINE >> "output1.txt"
- else
- count=0
- echo $LINE >> "output2.txt"
- fi
- done < $FILENAME
No comments:
Post a Comment