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
Displaying specific lines in a file. MaestroRage UNIX for Dummies Questions & Answers 3 02-05-2008 04:57 PM
How do you specific lines in a file? hedgehog001 UNIX for Dummies Questions & Answers 2 08-23-2005 12:04 AM
Cutting specific name from configuration file nir_s Shell Programming and Scripting 8 03-01-2005 11:38 AM
Cutting n consecutive lines from a file... Vishnu UNIX for Dummies Questions & Answers 2 10-18-2002 10:49 AM
extract specific lines from file apalex UNIX for Dummies Questions & Answers 2 05-15-2001 09:57 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 3.00 average. Display Modes
  #1 (permalink)  
Old 06-02-2005
pathanjalireddy pathanjalireddy is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 21
Exclamation Cutting specific lines from a file

Hi,

I have a file named Mani.txt. The contents are like this

cat Mani.txt
--------------------------------------------------------
Hi there how r u

My Name is Mani

Bye
------------------------------------------------------------
I want to cut the first and last lines from the file Mani.txt. I want the output file to contain only the line 'My Name is Mani'.

Please help me out. If , possible give me a snippet of the code

Thanx in advance
  #2 (permalink)  
Old 06-02-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
This should do it... but the script will work only for your mani.txt.

Code:
sed -e '/^My Name/!d mani.txt > output.txt
Vino
  #3 (permalink)  
Old 06-02-2005
pathanjalireddy pathanjalireddy is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 21
hi,
in sed -e '/^My Name/!d mani.txt > output.txt- where to close the quote
  #4 (permalink)  
Old 06-02-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Sorry about that.

Code:
sed -e '/^My Name/!d' mani.txt > output.txt
Vino
  #5 (permalink)  
Old 06-02-2005
pathanjalireddy pathanjalireddy is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 21
Hi,

Thanx. What should I do if want the first and last line of Mani.txt
I have a file called Log.txt. The contents of the file are
--------------------------------------------------------------------------

Creating Control File for sqlloader
Control file (data.ctl) Created for sqlloader
The execution of tool has started at Tue, May 31, 2005 03:45:37 AM
The User running the tool is DACSCAN
The present working directory is /usr/dacscan/toolbin
Temporary Table Created for Updating the Original Table
Temp Table have been created for storing the updated Records
Updation Successfully Completed on the Original Table
SQL> select * from spr1;

DOMAIN_NAME CKT COLOR SYS_UPDATE
-------------------- ------------------------------ ----- ----------
AREA_hickory 76L/37_690021/7JK1-711020/7JK1 R Y
AREA_hickory 76L/37_690021/7JK1-711020/7JK2 G N
AREA_aspen 76L/37_690021/7JK1-711020/7JK1 R Y

SQL> spool off;
Temp Table for storing updated records have been dropped
Temp Table created for updating the original Table is Dropped
All the Original Files have been moved to /dacscan/trace Folder
The execution of tool has finished execution at Tue, May 31, 2005 03:45:48 AM
The tools execution time is from Tue, May 31, 2005 03:45:37 AM to Tue, May 31, 2005 03:45:48 AM
------------------------------------------------------------------------

I want to remove the sentences SQL>select * from spr1 and
SQL> spool off;

What should I do

Thanx in advance
  #6 (permalink)  
Old 06-02-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
As I understand, you want to remove lines containing SQL.

This is what you do (using sed).

Code:
sed -e '/SQL/d' Log.txt > output.txt
It says for every line that is read, if you encounter SQL, delete the line. Whatever is not deleted gets into output.txt

For your Mani.txt,

Code:
tail -1 Mani.txt > Mani.txt.lastline
gives you the last line.

Similarily

Code:
head -1 Mani.txt > Mani.txt.firstline
Vino
Reply

Bookmarks

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 12:22 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