[SATLUG] Shell scripting challenge

Enrique Sanchez Vela esanchezvela at yahoo.com
Mon Apr 6 15:37:04 CDT 2009



> What does this <if [ -f xxf ]> line mean?? I am sorry
> for asking this,
> cos I know I mentioned that I have some basic knowledge of
> bash & c++
> but I am just realizing that they are hopelessly inadequate
> :-(
> 

the <if [ -f xxf ] > line means that if the file with name xxf exists, then 
 append the contents of the sixth file into the 5th.

the split command splits the files using -l <LINES> each, so it will create 5 files of $j lines and one more with the reminding ones, that is why I test whether the file exists or not, if it exists, then append the output to the 5th file.

somehow the command I originally sent is flawed, the correct script is...

 rm -f xaf
 lc=$(wc -l file| awk '{print $1}')
 ((j=lc/5))
 split -l $j file
 if [ -f xaf ] ; then cat xaf >> xae ; rm -f xaf; fi

the awk '{print $1 }' ; does split the input line and print only the first field ignoring spaces.

best regards,
esv.




      


More information about the SATLUG mailing list