PDA

View Full Version : [SOLVED] sed trouble in bash script



conradin
August 28th, 2012, 07:12 PM
Hi all,
I want to bring up a line of text one line at a time, I thought, and easy enough task for sed. The wc bit makes the count whatever the number of lines is.
I get the error:"sed: -e expression #1, char 3: unknown command: `.'"
also, how can I separate the variable "i" from the sed argument "p"? I am wondering if a space or lack of space is causing the issue. Ive tried both, neither work.

Can someone point out how to fix this?
But I get an error, I cant seem to figure out.


#!/bin/bash
set -vx
sometime=5
length=`wc -l someFile | grep -o *[0-9]`

for i in {1..$length..1}
do
sed -n $ip someFile
sleep $sometime
done

Bachstelze
August 28th, 2012, 07:24 PM
For your last question, you can use quotes:


firas@aoba:~$ i=foo
firas@aoba:~$ echo "$i"p
foop

sisco311
August 28th, 2012, 09:44 PM
Check out BashFAQ 001, 082, 011 and http://mywiki.wooledge.org/BraceExpansion




while read -r line
do
printf '%s\n' "$line"
sleep 5
done < filename

conradin
August 30th, 2012, 03:30 PM
Thanks sisco! That helps!