Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, everyone,
I am writting a script to make many data files from a single input. The idea is, take a 50 line input as an example, that the script will take line1-15 as file1, line2-16 as file2, line3-17 as file3, and so on until line36-50 as file36.
I assembled two scripts as following, but there is always error message. Because I am not really good on this, just post here to see if anyone can help me.
It seems that some lines I am trying to post will be missed.
Thanks in advance.
1st:
#!/bin/sh
nr=`wc $1 | nawk '{print $1}'`
for (j=1; j file
close(file)
}
}' $1
done
-----------------
2nd:#!/bin/sh
nr=`wc $1 | nawk '{print $1}'`
for (j=1; j file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
close(file)
}
}
}' $1

Done in KSH, but it worked fine for me.
The $startnumber and $readwidth variable basically control the whole thing, you can play with them to get different results, but ideally they should be the same as the startnumber is for the head command (it will read the first $startnumber lines) and the readwidth will tail the last $readwidth lines of that initial head. So if you have $startnumber as 17 the $readwidth will then read lines 3-17. Anyway im sure you get the idea. Try it, see if it works.#!/bin/ksh
linesinfile=`wc -l testfile|awk '{print $1}'`
startnumber=15
readwidth=15
filenumber=1until [[ $startnumber -eq $(($linesinfile+1)) ]];do
head -$startnumber testfile | tail -$readwidth > file$filenumber
startnumber=$(($startnumber+1))
filenumber=$(($filenumber+1))
done

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |