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
sed remove last 10 characters of a line start from 3rd line minifish Shell Programming and Scripting 7 03-26-2008 04:42 PM
Deleting lines above a certain line eltinator Shell Programming and Scripting 3 10-11-2007 03:29 PM
deleting newline characters but not the "true" \n character caddyjoe77 Shell Programming and Scripting 1 08-15-2007 11:21 PM
Checking the last line and deleting srivsn Shell Programming and Scripting 3 12-13-2005 02:04 PM
Deleting the blank line in a file and counting the characters.... rkumar28 Shell Programming and Scripting 4 04-17-2005 01:13 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-15-2006
scotbuff scotbuff is offline
Registered User
  
 

Join Date: Jun 2005
Location: Middletown, PA
Posts: 73
Deleting First Two Characters On Each Line

How would one go about deleting the first two characters on each line of a file on Unix? I thought about using awk, but cannot seem to find if it can explicitly do this. In this case there might or might not be a field separator. Meaning that the data might look like this.

01999999999
02999999999
09999999999

Regardless of what it looks like, on each line I want the first two characters deleted. I thought I would run it by the group here, I know I am probably missing something easy. Thanks in advance.
  #2 (permalink)  
Old 12-15-2006
mudhireddy mudhireddy is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 10
You can use sed like

sed 's/^..//g' FILE_NAME
  #3 (permalink)  
Old 12-15-2006
scotbuff scotbuff is offline
Registered User
  
 

Join Date: Jun 2005
Location: Middletown, PA
Posts: 73
Sweet

Thanks so much, I need to brush up on my regex, I knew there was an easy way, just did not dawn on me at the time. Thanks again.
  #4 (permalink)  
Old 12-15-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807

Code:
cut -c 3- filename > newfilename

  #5 (permalink)  
Old 12-16-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
awk '{ print substr($0,3) }' f1

  #6 (permalink)  
Old 12-16-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,557
Python alternative, no regexp


Code:
#!/usr/bin/python
for line in open("file"):
     print line[2:]

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 02:03 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