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
donebut nothing happens. Doesn't even echo "succeeded". Any idea why?
72 Answers
Use sed as following:
sed 's/^.//' fileFor line if starts with spaces:
sed 's/\S//' fileMatches 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:]]//' fileor
sed 's/[^[:space:]]//' fileor
sed 's/[[:alpha:]]//' fileor contains numbers:
sed 's/[[:alnum:]]//' fileor 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>