The UNIX and Linux Forums  

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
remove a line within a file new2ss UNIX for Dummies Questions & Answers 3 11-23-2008 02:34 PM
sed remove last 10 characters of a line start from 3rd line minifish Shell Programming and Scripting 7 03-26-2008 04:42 PM
SED help (remove line::parse again::add line) Malumake Shell Programming and Scripting 6 10-24-2007 06:02 PM
Remove header(first line) and trailer(last line) in ANY given file madhunk Shell Programming and Scripting 2 03-13-2006 03:36 PM
Remove first 15 line bobo UNIX for Dummies Questions & Answers 6 01-30-2006 09:26 PM

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 12-19-2006
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
remove line 1 and save it....

Hi,

I have txt file like below:

[0000.0217] report date
[0000.0288] 1234567
[0000.0291] 2345234
[0000.1312] 8976542

How can I skip to read line 1 and grep the number 288, 291 and 1312 and save into another new txt file?
  #2 (permalink)  
Old 12-19-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
assuming you don't want these numbers ANYWHERE on the line, but rather as a second pair of numbers separated by '.' and enclosed inside the '[]'.

one 'ugly' way (that works for most sed-s):
Code:
sed -n '2,$s/.*288].*/&/p;2,$s/.*291].*/&/p;2,$s/.*1312].*/&/p' happy.txt
the 'saving' part is left as an exercise to the OP.

Last edited by vgersh99; 12-19-2006 at 10:02 PM..
  #3 (permalink)  
Old 12-19-2006
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
Quote:
Originally Posted by vgersh99
assuming you don't want these numbers ANYWHERE on the line, but rather as a second pair of numbers separated by '.' and enclosed inside the '[]'.

one 'ugly' way (that works for most sed-s):
Code:
sed -n '2,$s/.*288].*/&/p;2,$s/.*291].*/&/p;2,$s/.*1312].*/&/p' happy.txt
the 'saving' part is left as an exercise to the OP.
thank you for the suggestion. However, the number like 288, 291, 1312 is not the same everyday (because of the txt file created from someone and i only need the thesee number). How can I do it?
  #4 (permalink)  
Old 12-19-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,552
if you have Python installed and assume only a dot in each line.
Code:
#!/usr/bin/python
f=open("file")
f.readline()
for line in f:
     whereisdot = line.index(".")
     whereisclosebracket = line.index("]")
     print line[whereisdot + 1: whereisclosebracket ]

Last edited by ghostdog74; 12-20-2006 at 02:03 AM..
  #5 (permalink)  
Old 12-20-2006
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
Quote:
Originally Posted by ghostdog74
if you have Python installed and assume only a dot in each line.
Code:
#!/usr/bin/python
for line in open("file"):
     whereisdot = line.index(".")
     whereisclosebracket = line.index("]")
     print line[whereisdot + 1: whereisclosebracket ]
Sorry, the server haven't Python installed. any suggestion?
and the first line should not be read as well..
  #6 (permalink)  
Old 12-20-2006
cskumar cskumar is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 67
try this one

awk 'FNR == 1 {next} match($0 ,("288|291|1312")) {print substr($0,RSTART,RLENGTH)}' File > file1.txt
Closed Thread

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 07:27 AM.


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