Star Hype News.

Premium celebrity moments with standout appeal.

news

Deleting first letter of each line

By Sophia Vance

I have a file and I need to delete its first letter of each lines. I tried this:

for i in
do
if [ $5 -eq cat harfler | grep `head -n i harfler | head -c 1` ]
then
echo "succeded"
tr -d `head -n i`
fi
done

but nothing happens. Doesn't even echo "succeeded". Any idea why?

7

2 Answers

Use sed as following:

sed 's/^.//' file

For line if starts with spaces:

sed 's/\S//' file

Matches any non-white space character but not newline. You can use \w or [A-Za-z0-9_] instead.

The command suggested by @gleenjackman:

sed 's/[^[:blank:]]//' file

or

sed 's/[^[:space:]]//' file

or

sed 's/[[:alpha:]]//' file

or contains numbers:

sed 's/[[:alnum:]]//' file

or use:

while read line; do echo "${line:1}" ;done < file
2

You can achieve this using

sed -

sed 's/^.\{1\}//g' <filename>

cut -

cut -c 2- <filename>

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy