urgent help needed regarding splitting file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting urgent help needed regarding splitting file
# 1  
Old 03-04-2010
urgent help needed regarding splitting file

how can i split a file on last record ? say i have a file A with 4 records as follows :

first line
second line
third line
last line

I want to make two files B and C

with contents of B as
first line
second line
third line

and the contents of C as
last line
# 2  
Old 03-04-2010
Try this,

Code:
sed -n '$!p' A > B ; sed -n '$p' A > C

# 3  
Old 03-04-2010
You try this.

Code:
sed -n '$!p' A > B (or) sed '$d' A > B
sed '$!d' A > C (or) sed -n '$p' A > C

# 4  
Old 03-04-2010
You can use the following commands also
Code:
head -n 3 A > B

Now the B file will contain

first line
second line
third line

Code:
tail -n 1 A > C

Now the C file will contain

last line
# 5  
Old 03-04-2010
Thillai,your second approach which is to copy the last line of a file into C is OK.But,the first command has to be like this.Because,we can't sure that there are only four lines in a file.

Code:
head -n -1 A > B

# 6  
Old 03-04-2010
Good try. But Here the user mentioned that there are 4 records only in the file A.
Kindly refer that.
# 7  
Old 03-04-2010
Bug

Try the following line,

sed '$d' A > B ; sed '$!d' A > C

B file contents:
--------------------
first line
second line
third line

C file content:
-------------------
last line

Last edited by rekha_sri; 03-04-2010 at 02:37 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

URGENT HELP NEEDED

KING KONG ELECTRICITY AUTHORITY BILL CALCULATOR You are required to develop a script that will enable KING KONG ELECTRICITY AUTHORITY to calculate customer bills based on their meter readings. The customers are categorized into the following categories:  Residential customers  Commercial... (1 Reply)
Discussion started by: watisevil
1 Replies

2. Shell Programming and Scripting

Urgent Help needed !!!

Hi, I have a directory, where i get 4 files for each day... The files will be generated at any time. I am trying for a shell script for copying the file from this directory whenever new file is generated. Say for example : If the directory X has following files A1,A2,A3,A4,B1,B2,B3,B4...... (2 Replies)
Discussion started by: krishh.kk
2 Replies

3. UNIX for Dummies Questions & Answers

Urgent Help Needed

Hello Friends, I am a Graduate in Computers. I completed BCA degree this year. I want to make my career in UNIX. But, unfortunately I don't know anybody who can guide me. I am totally confuse because I don't know where to start and what are the future prospect in UNIX. Please give your... (4 Replies)
Discussion started by: Luckyless
4 Replies

4. Shell Programming and Scripting

Urgent Help Needed.

Hi, Below is my issue which I desperately need and I want a shell script which can do this job. I need this script as I m planning to put this for a system health check. Please assist me. 1. There are 10 log files in a particular location. 2. open each log file. Goto to the end of the... (1 Reply)
Discussion started by: kashriram
1 Replies

5. UNIX for Advanced & Expert Users

Urgent help needed!!!

-------------------------------------------------------------------------------- hy guys, i got few interview questions i need someone to answer urgently: 1)If you cant get to the root, you try to fsck it, but gets errors to read file systems. What steps do you take to recover the host... (1 Reply)
Discussion started by: charneet
1 Replies

6. Shell Programming and Scripting

URGENT HELP NEEDED ON -File size reading

All Expert, I am using Sun OS 5.8 and Perl version 5 in One server and Perl 5.8 in another unix server. I am able to read a file using fopen function of perl --file size having more then 3 GB of data.(In the machine where Perl 5.8 install) But when i am running the same perl script --It... (1 Reply)
Discussion started by: jambesh
1 Replies

7. UNIX for Dummies Questions & Answers

Urgent help needed to delete some text without opening the file in unix

Hi To delete some text in 2 files in line1 ( not complete line) in unix without opening the files. For example: source file is like this <?xml version="1.0"... (5 Replies)
Discussion started by: pyaranoid
5 Replies

8. Windows & DOS: Issues & Discussions

Urgent XP help needed Please

Hi, Please accept my apologies if I have not explained anything clearly enough but i am a little old on new lingo!!! I am running XP from home and last night the following happened. After being logged on for pretty much the full day, I had what seemed like a pop up come up. Although most pop... (3 Replies)
Discussion started by: nike1601
3 Replies

9. Shell Programming and Scripting

urgent help needed.

Ok I admit it I am stumped and I would appreciate any and all help Here is what I am trying to do. Korn Shell script I am setting a variable to another shell script that I want to invoke in my main script like so: GETDIR=/vol100/cfg/.getdir The .getdir shell script take a parameter,... (4 Replies)
Discussion started by: Batch
4 Replies

10. Shell Programming and Scripting

urgent help needed !!

i have a script, which is continuously looping. i want to view the script name when i use ps command... it is only showing -sh ... UID PID PPID C STIME TTY TIME COMMAND informix 8533 20923 0 18:19:28 pts/ta 0:00 -sh but i dont have my scriptname displayed .... how can i do that my script is... (0 Replies)
Discussion started by: guhas
0 Replies
Login or Register to Ask a Question