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
Trying to remove '^M' characters from a file. Krispy Shell Programming and Scripting 13 05-12-2009 05:46 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
How to remove FIRST Line of huge text file on Solaris madoatz UNIX for Dummies Questions & Answers 5 06-23-2007 01:19 PM
how to remove line greater then 3000 characters. naren_14 UNIX for Advanced & Expert Users 10 06-15-2005 11:00 PM
Replacing all but last Hex characters in a text line BAH Shell Programming and Scripting 2 03-26-2004 04:00 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 Rate Thread Display Modes
  #1 (permalink)  
Old 10-29-2008
ajp7701 ajp7701 is offline VIP Member  
Supporter
  
 

Join Date: Dec 2007
Posts: 63
sed to remove 1st two characters every line of text file

what is the sed command to remove the first two characters of every line of a text file?
each line of the text file has the same amount of characters, and they are ALL NUMERIC. there are hundreds of lines though.
for example,

>cat file1.txt
10081551
10081599
10082234
10082259
20081134
20081159
30082232
10087721
>

I want the end result to remove the first two digits of each line

>cat file2.txt
081551
081599
082234
082259
081134
081159
082232
087721
>

Thank you so much!!
  #2 (permalink)  
Old 10-29-2008
migurus migurus is offline
Registered User
  
 

Join Date: Sep 2008
Location: US
Posts: 49
cat input_file | sed 's/^..//' > output_file
  #3 (permalink)  
Old 10-29-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

Code:
sed 's/^..//' file1.txt > file2.txt
  #4 (permalink)  
Old 10-29-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
man sed to see if your version support -i option.
Code:
sed -i 's/\(.\{2\}\)//' file
  #5 (permalink)  
Old 10-29-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Or even:

Code:
sed  's .\{2\}  ' infile
If your sed supports the -r option:

Code:
sed -r 's .{2}  ' infile
Or:

Code:
sed  's ..  ' infile
  #6 (permalink)  
Old 10-29-2008
ajp7701 ajp7701 is offline VIP Member  
Supporter
  
 

Join Date: Dec 2007
Posts: 63
thank you!

thank you all! I'll probably make a new post, but I actually need the last two characters removed also....
>cat file1.txt
10081551
10081599
10082234
10082259
20081134
20081159
30082232
10087721
>
ends up looking like:
>cat file1.txt
100815
100815
100822
100822
200811
200811
300822
100877
>
  #7 (permalink)  
Old 10-29-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Code:
sed 's ..$  ' infile
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 08:27 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