Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Csplit command problem in Linux

$
0
0
Hi All,

I have recently join the forum and this is my first post....hoping to get a suggestion to a problem that I am facing.

I have a script that works well on ksh unix on AIX server. The below mentioned code checks number of records in an input file starting with 99 and splits it accordingly and creates new files. i.e. if there are two records starting with 99 then two new files are created.

Format of data in the input file:
10ABC 20150624
99ABC 20150624
10DEF 20150624
99DEF 20150624


Code:

SPLTNME=${FILENAME}_${$}
#--getting no. of footer records in the file
NUM=`grep "^99" ${FILENAME} | wc -l`
REPEAT=`expr $NUM - 2`
csplit -n4 -s -k -f ${SPLTNME} ${FILENAME} /^99/1 {$REPEAT} > /dev/null 2>&1

In case if there is a single 99 record in the input file, the value of REPEAT is set to -1. In AIX the code works and it looks like

Code:

csplit -n4 -s -k -f ${SPLTNME} ${FILENAME} /^99/1 {-1} > /dev/null 2>&1
Now, I am trying to run the same script in Linux, but the above "csplit" code is not working.

The "-1" value of repeat is not recognised in linux. I guess it only recognises postive integers where pattern repeatation is mentioned.

To fix this, I tried hardcoding positive value like 1...it worked but created two files instead and out of the two, one is 0 byte file. It seems that the above csplit code line needs modification in order to run it in Linux.

Could you please suggest any alternative to make this part of the code work in linux.

Details of Linux version is: Red Hat Linux release 6.6 (Santiago)
shell: ksh

Thanks,
Sanjay

Viewing all articles
Browse latest Browse all 16232

Trending Articles