Require script to create two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Require script to create two files
# 1  
Old 12-08-2009
Require script to create two files

Hi folks,

I have a input.file with the following contents:-

flor
geor
enta
vpal
domi
pegl
cars
mted
four
rose
annc
gabi
ward
dalv
elph
beac
qtwn
jame
gabr
rivl
birc
radi
grey
mark
mast
entr
hunt
rivr
doms
domr
vpsc

I want to break this up into two output files. The sequence is very important. The 1st record can go to any output file as long as the next record goes to the opposite file.

Example,
Output.FileA will look like:-
flor
enta
domi
cars
four
annc
ward
elph
qtwn
gabr
birc
grey
mast
hunt
doms
vpsc

Output.FileB will look like:-
geor
vpal
pegl
mted
rose
gabi
dalv
beac
jame
rivl
radi
mark
entr
rivr
domr

Any script guru to help with this?
# 2  
Old 12-08-2009
Can you show us what you've tried so far?
# 3  
Old 12-08-2009
This should work
Code:
while read LINE
do
    echo "$LINE" > Output.FileA
    read LINE && echo "$LINE" > Output.FileB
done

# 4  
Old 12-08-2009
Code:
nawk 'BEGIN{file0="a.txt";file1="b.txt"}
{
tmp=NR%2
file=sprintf("file%s",tmp)
print $0 >> file
}' a.txt

# 5  
Old 12-08-2009
Code:
awk '{print > "a.txt" ; getline; print > "b.txt"}' urfile

# 6  
Old 12-09-2009
Quote:
Originally Posted by rdcwayx
Code:
awk '{print > "a.txt" ; getline; print > "b.txt"}' urfile

SmilieSmilieSmilie
# 7  
Old 12-09-2009
Another one:

Code:
awk '{print > "file_"NR%2}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help require to edit multiple files

I have 6 different pipe delimiter files. My loads failing due to missing company code. File1: 31 st field is company code. 402660076310|2014-12-10 17:22:39|2280361|MRYKI|1||CA|92507|US||1|1|0|0|0||N|A1|ONT|1001891771660009250700402660076310|WM|0201|RALA |2014-12-12|5|2014-12-12|5||FRI - 12... (4 Replies)
Discussion started by: srikanth38
4 Replies

2. Shell Programming and Scripting

How to create or convert to pdf files from csv files using shell script?

Hi, Can anyone help me how to convert a .csv file to a .pdf file using shell script Thanks (2 Replies)
Discussion started by: ssk250
2 Replies

3. HP-UX

Need help to create a script to delete the files

Hi All, I want to delete all core* files in below file system in Unix server. File system: /usr/sap/P01/JC00/j2ee/cluster/server0 I want to setup a cron job every ten minutes to delete the core *files Thanks N Rao (2 Replies)
Discussion started by: YNRao24
2 Replies

4. Shell Programming and Scripting

Need help to create a script to delete the files

Hi All, I want to delete all core* files in below file system in Unix server. File system: /usr/sap/P01/JC00/j2ee/cluster/server0 I want to setup a cron job every ten minutes to delete the core *files Thanks N Rao This thread duplicates another thread with the same title: Need... (1 Reply)
Discussion started by: YNRao24
1 Replies

5. Shell Programming and Scripting

How to create a script to compare 2 files?

I have two files File1 and File2 will contains same number of fields. The rows in File1 can be found anywhere in File2. If any rows from File1 doesn't match to File2 then write those records to a File1 log file. If any rows from File2 doesn't match to File1 then write those records to a File2... (6 Replies)
Discussion started by: ranjanp
6 Replies

6. Shell Programming and Scripting

How to automate a script that would require authentication?

Hey everyone... I'm just stretching my wings a bit and seeing how things work. If I wanted to write a script that had me ssh to my remote computer, how can this be done? If the script runs without me, how can I enter the required password? the same is true for any time of authentication method like... (2 Replies)
Discussion started by: Lost in Cyberia
2 Replies

7. Shell Programming and Scripting

script to create files on solaris 10

Hello, To learn ZFS, i try to create pool . and for that i want create 10 files with 512MB (because i dont have multiple disks and multiple controllers) ADMIT THAT THIS IS TEN HIGH-PERFORMANCE HARD DRIVES To get this 10 files,all of them have the same size : 512MB, I do these... (0 Replies)
Discussion started by: herbich1985
0 Replies

8. Programming

REQUIRE HELP IN WRITING A PERL SCRIPT

Hi everyone I am a beginner in perl and I am trying to write a perl script. Basically I want to separate gene entries from phenotype entries in a text file which contains huge number of records and copy them in a separate file. The gene entries will have * symbol after the line FIELD TI. A... (7 Replies)
Discussion started by: kaav06
7 Replies

9. Shell Programming and Scripting

Script to create files

Requirement:- SQLs select name from v$datafile; select name from v$controlfile; select name from v$tempfile; select MEMBER from v$logfile; These sqls has to run in one script and o/p of each sql has to write in seperate files.But the o/p is like if we issue select name from... (2 Replies)
Discussion started by: Sanal
2 Replies

10. Shell Programming and Scripting

Require Help for Shell Script

Hi friends, i am trying to print warning for partition size which exceed limit of 90% & other are ok. i m using below command which print partition which exceed 90% # df -h | sort -k5 | head -1 | awk 'END{ print $1" :- Not Having more space on This Partition"}' i want to print... (14 Replies)
Discussion started by: jagnikam
14 Replies
Login or Register to Ask a Question