Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
sed 's/.\(.*\)/\1/' myfile

Say myfile contains:

abc
def
ghi

I want to remove the first character only from the first line but the above removes it from all the line.

share|improve this question
add comment

3 Answers 3

up vote 9 down vote accepted

Maybe sed '1s/.\(.*\)/\1/' myfile?

share|improve this answer
    
thank you very much –  munish Feb 24 '12 at 5:57
2  
Capturing groups slows down the regular expressions. Better do it without them: sed '1s/.//' myfile. –  manatwork Feb 24 '12 at 15:35
add comment

can also use awk: awk 'NR==1 {sub(/./,"")} 1'

share|improve this answer
add comment

tail can read from a byte offset, so if your file uses only single-byte characters (typically UTF-8 ASCII), this will work.

It depends on your situaton, whether it is improtant to you or not, but tail is faster than sed... probably becaue sed needs to process each line inndividually, ... But don't use it where there is any chance of the first character using more than one byte.

tail -c +2 "file"  

From man tail

-c, --bytes=N output the last N bytes; alternatively, use +N to output bytes starting with the Nth of each file

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.