sed to remove 1st two characters every line of text file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

sed to remove 1st two characters every line of text file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-29-2008
ajp7701 ajp7701 is offline VIP Member  
Supporter
 
Join Date: Dec 2007
Last Activity: 12 July 2013, 1:12 PM EDT
Posts: 84
Thanks: 1
Thanked 0 Times in 0 Posts
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!!
Sponsored Links
    #2  
Old 10-29-2008
migurus migurus is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 28 July 2014, 6:45 PM EDT
Location: US
Posts: 205
Thanks: 23
Thanked 20 Times in 19 Posts
cat input_file | sed 's/^..//' > output_file
Sponsored Links
    #3  
Old 10-29-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
 
Join Date: Mar 2007
Last Activity: 25 July 2014, 8:14 PM EDT
Location: Toronto, Canada
Posts: 2,877
Thanks: 0
Thanked 110 Times in 102 Posts


Code:
sed 's/^..//' file1.txt > file2.txt

    #4  
Old 10-29-2008
danmero danmero is offline Forum Advisor  
 
Join Date: Nov 2007
Last Activity: 29 July 2014, 6:33 AM EDT
Location: H3X
Posts: 2,151
Thanks: 10
Thanked 117 Times in 110 Posts
man sed to see if your version support -i option.

Code:
sed -i 's/\(.\{2\}\)//' file

Sponsored Links
    #5  
Old 10-29-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 29 July 2014, 10:19 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,664
Thanks: 182
Thanked 617 Times in 575 Posts
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

Sponsored Links
    #6  
Old 10-29-2008
ajp7701 ajp7701 is offline VIP Member  
Supporter
 
Join Date: Dec 2007
Last Activity: 12 July 2013, 1:12 PM EDT
Posts: 84
Thanks: 1
Thanked 0 Times in 0 Posts
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
>
Sponsored Links
    #7  
Old 10-29-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 29 July 2014, 10:19 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,664
Thanks: 182
Thanked 617 Times in 575 Posts

Code:
sed 's ..$  ' infile

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove new line characters from a file saini UNIX Desktop for Dummies Questions & Answers 1 04-20-2012 05:06 PM
Remove characters from text shoaibjameel123 Shell Programming and Scripting 4 08-30-2011 10:58 AM
remove ANSI Escape characters from text file jwzumwalt UNIX for Advanced & Expert Users 1 08-26-2010 09:25 AM
Remove special characters from text file kkb Shell Programming and Scripting 10 12-07-2009 10:14 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



All times are GMT -4. The time now is 10:47 AM.