Spliting a file and renaming it's out put


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Spliting a file and renaming it's out put
# 1  
Old 02-13-2009
Error Spliting a file and renaming it's out put

Hi friends,
I am new to unix. With the help of this site I wrote a script. But it's returning some errors pls help.Smilie

Here is my specifications:
I have a file obsrec_31583_090212.xls at /home/lingalma/temp/cdl I want it to mv to another temp folder called /home/lingalma/temp/obsrec and check if itcontains more than 65000 rows. If so split the file and rename the files.

My script is:
Code:
#!/bin/csh -vdb
cd /home/lingalma/temp/cdl
FN =`ls -lrt obsrec* | tail -1 | awk '{print $9}'`
DN =`ls -lrt obsrec* | tail -1 | awk '{print $9}'| awk -F. '{print $1}'`
 
#FN should be obsrec_31583_090212.xls, and DN should be obsrec_31583_090212

cp $FN /home/lingalma/temp/obsrec
cd /home/lingalma/temp/obsrec
if [ wc -l $FN => "65000"];
then
split -l 65000 $FN $DN
rm -f $FN
NUM=1
ls | while read line
do
mv $line $DN_$NUM.xls
$(( NUM + 1 ))
done
fi
EOF


Error message is:
Code:
 
cd /home/lingalma/temp/cdl
FN =`ls -lrt obsrec* | tail -1 | awk '{print $9}'`
FN: Command not found
DN =`ls -lrt obsrec* | tail -1 | awk '{print $9}'| awk -F. '{print $1}'`
DN: Command not found
cp $FN /home/lingalma/temp/obsrec
FN: Undefined variable

Please advise how can I correct these errors.

Last edited by zaxxon; 02-13-2009 at 10:21 AM.. Reason: added code tags
# 2  
Old 02-13-2009
1. Use code tags when posting code, logs or data, ty.
2. Remove the blanks between the variable name, the = sign and the value following like FN=123.
# 3  
Old 02-13-2009
Hi Zaxxon.. Sorry abt that tag thing. As it is my first post.. i am not aware of it's importence.


Thanks for your reply. But again I am getting some errors. Please help me.

Code:
cd /home/lingalma/temp/cdl
FN=`ls -lrt obsrec* | tail -1 | awk '{print $9}'`
FN=obsrec_31583_090212.xls: Command not found
DN=`ls -lrt obsrec* | tail -1 | awk '{print $9}'| awk -F. '{print $1}'`
DN=obsrec_31583_090212: Command not found
cp $FN /home/lingalma/temp/obsrec
FN: Undefined variable


Last edited by zaxxon; 02-13-2009 at 10:21 AM.. Reason: added code tags
# 4  
Old 02-13-2009
what version of unix are you running? and what shell?
# 5  
Old 02-13-2009
I currently don't see the error... Maybe try enclosing the backticks by double quotes:
Code:
FN="`ls -lrt obsrec* | tail -1 | awk '{print $9}'`"

Also this with the preceding cd to /home/lingalma/temp/cdl should directly work on the shell's command line. Echoing $FN should show the ouput.

Edit:
I added code tags to your post, you can see them in the source when you enter the edit mode of your old posts up there. They don't only help for readability but also preserve spaces etc.

Last edited by zaxxon; 02-13-2009 at 10:23 AM..
# 6  
Old 02-13-2009
I am using SunOS 5.8

Last edited by raaj.manoj; 02-14-2009 at 02:01 AM..
# 7  
Old 02-13-2009
he's using csh.

you have to set variables like so:

Code:
set x=alkshdlkahslhdlfkhasdf

not just:
Code:
x=alshdaklshf

Also, => is not a valid comparision operand.

You mean >=
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP batch not renaming file with "put"

I have a .ksh script that creates an sftp batch file and runs it through sftp. It works except for one thing. If I try to "put" to a different name, it doesn't use the specified remote name...it still "puts" the original local name. I've tried both of these, and neither work...it will always... (4 Replies)
Discussion started by: dbiggied
4 Replies

2. Shell Programming and Scripting

Spliting log file

Hello, I want to split or cut a large size log file by year wise(eg 2009, 2010) .But the source file must not have the splited or cut lines after this process ,all of them must move to the destination folder.Does grep command have the fuctionality like cut and paste? I used grep -Ev command but... (17 Replies)
Discussion started by: jobycxa
17 Replies

3. Shell Programming and Scripting

Spliting file based field pattern

Hi all, i have file that looks like as below 2263881188,24570896,439,SOLO,SOLO_UNBEATABLE,E,+3.13,+0.00 2263881964,24339077,439,SOLO,SOLO_UNBEATABLE,F,-0.67,+0.00 2263883220,22619162,228,Bell,Bell_MONTHLY,E,-2.04,+0.00 2263883220,22619162,228,Bell,Bell_MONTHLY,F,-2.04,+0.00... (3 Replies)
Discussion started by: raghavendra.cse
3 Replies

4. Shell Programming and Scripting

spliting up a large file

Dear All, I have a very large file which which i would like split into indvidual frames evrytime the line ends with "ENDMDL" and then name frame1.pdb frame2.pdb etc can any one give me a few sugeestions? ideally i would like to have ENDMDL at the end of each frame or not pressent at all. an... (4 Replies)
Discussion started by: Mish_99
4 Replies

5. Shell Programming and Scripting

File Spliting problem

I have a very big log file which looks like this: I need to split this file and create files with "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" as the delimiter. The file names need to be the contents of the next line after the delimiter(FIRST_ITEM,SECOND_ITEM...so on..). (7 Replies)
Discussion started by: engineer
7 Replies

6. UNIX for Dummies Questions & Answers

spliting a file

how would i split the file "file1" into smaller files containg lines of 15 (1 Reply)
Discussion started by: JamieMurry
1 Replies

7. UNIX for Dummies Questions & Answers

Caching while spliting a large file

Hi The scenario is like this. I need to split 5 files having size 3GB, 2GB, 4GB, 30GB and 20 GB respectively. The machine has 15GB heap space. Before starting split proces it was showing 15gb free space. Once the split process completed it showed 100 mb free and around 12GB cached. My... (3 Replies)
Discussion started by: siba.s.nayak
3 Replies

8. Shell Programming and Scripting

Spliting the file dynamically

i am creating the file , when this file reaches the size 2 GB, i need one message or fire (4 Replies)
Discussion started by: kingganesh04
4 Replies

9. Shell Programming and Scripting

Spliting file based on condition

Hi, I have a comma separated file with millions of records in it. I have a requirement to split the file based on the value in a one of the columns. Suppose i have a text file with columns like C1, C2,C3,C4 Column C4 can hold the values either 01 or 02 03 or 04. I nned to extract... (2 Replies)
Discussion started by: Raamc
2 Replies

10. UNIX for Dummies Questions & Answers

spliting up a huge file

I have a file {filename} which contains 65000 records I need to split into 6 smaller files roughly 11000 records each. Can someone advise me of the Unix command to do so ? Many thanks (2 Replies)
Discussion started by: grinder182533
2 Replies
Login or Register to Ask a Question