The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
split a file but output file is fixed RahulJoshi Shell Programming and Scripting 3 01-07-2009 11:05 PM
Split large file and add header and footer to each file ashish4422 Shell Programming and Scripting 1 04-15-2008 07:12 AM
Split a file with no pattern -- Split, Csplit, Awk madhunk UNIX for Dummies Questions & Answers 10 12-17-2007 12:57 PM
How to split file by tags inside file? spookyrtd99 Shell Programming and Scripting 1 07-31-2006 01:50 AM
Split file using awk pvar Shell Programming and Scripting 8 07-21-2004 10:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-22-2009
dsshishya dsshishya is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 21
Split a file

Hi,


I want to split a file into 2 Files. The First 2 lines should be the First File with a Prefix to it and the rest of the file should be the Second with a Prefix.
When i am using the below command it gives me an error.
Please help.

Code:
head -2 $FILE_NAME >Header_$FILE_NAME
CNT=`wc -l $FILE_NAME`-2
tail -$CNT $FILE_NAME >Detail_$FILE_NAME
Thanks,
  #2 (permalink)  
Old 07-22-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,877
Probably because wc not only outputs the line count but also the filename. That, and you're not evaluating your expression. The CNT line should probably look something like this:
Code:
CNT=$(( $( wc -l | cut -d' ' -f1) - 2 ))
Or, much simpler:
Code:
sed -ne '1,2p' $FILE_NAME > Header_$FILENAME
sed -ne '3,$p' $FILE_NAME > Detail_$FILENAME
  #3 (permalink)  
Old 07-22-2009
dsshishya dsshishya is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 21
Thanks

Thanks Pludi....it works.....
  #4 (permalink)  
Old 07-22-2009
akrathi akrathi is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 41
You can make this script work after adding the third line
Thanks
Ashok

head -2 $FILE_NAME >Header_$FILE_NAME
CNT=`wc -l $FILE_NAME`-2
CNT=`echo $CNT | awk '{print $1 }'`
tail -$CNT $FILE_NAME >Detail_$FILE_NAME
Closed Thread

Bookmarks

Tags
break a file, file split, head and tail a file, split, splitting file

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0