Register
It is currently Tue Jul 22, 2014 7:10 pm

cut off the first character


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Thu Sep 22, 2011 5:19 pm   

Joined: Fri Jun 24, 2011 2:46 pm
Posts: 8
Dear everyone,

I'm looking for a very basic trick:

Cut the first letter (or special char) of each line of a file (dictionary).

I tried the cut command but it doesn't seems to work.

Awk one?

Thanks.


Top
 Profile  
 PostPosted: Thu Sep 22, 2011 11:25 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Code:
cut -c 2- inputfile.txt > outputfile.txt

You can't use the same file for both input and output at the same time.


Top
 Profile  
 PostPosted: Fri Sep 23, 2011 1:36 pm   

Joined: Fri Jun 24, 2011 2:46 pm
Posts: 8
thx


Top
 Profile  
 PostPosted: Tue Sep 27, 2011 11:02 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Sorry, I know it's after the fact but I <3 sed:
Code:
sed 's/^.//g' inputfile.txt > outputfile.txt


Top
 Profile YIM  
 PostPosted: Tue Sep 27, 2011 11:05 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
A good solution as well although the '/g(lobal)' option is a bit unnecessary (there will be no more than 1 beginning of line).
Added benefit is that you can use 'sed -i' and replace everything inline and not need a second file for (temporary) output.


Top
 Profile  
 PostPosted: Wed Sep 28, 2011 9:56 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Patsie wrote:
A good solution as well although the '/g(lobal)' option is a bit unnecessary (there will be no more than 1 beginning of line).
Added benefit is that you can use 'sed -i' and replace everything inline and not need a second file for (temporary) output.


All true! *headdesk*
My reply was too hasty :)


Top
 Profile YIM  
 PostPosted: Sun Oct 23, 2011 6:33 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
ZER.SHITMAKER wrote:
Awk one?

Code:
awk 'sub(/^./, _)' file > file.tmp && mv file.tmp file

Here, we remove the first character of each line of the file called « file », then redirect the result output to a file called « file.tmp », and finally rename it to "its" original name.

----

Patsie wrote:
Added benefit is that you can use 'sed -i' and replace everything inline and not need a second file for (temporary) output.


In fact, sed(1) uses temporary files, but it's transparent.
That's why I'd use this ed(1) solution instead:

Code:
ed -s file <<< $'s/^.//\nw'


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP