2

Could someone tell me what does this reply mean ?

sed: -e expression #1, char 4: unknown command: `
'

I get it when I use :

sed -n "$num"p $javaFile >> ~/Desktop/$1_sql.txt
for i in `seq 5 $max`
do
    lineNum=$(($num + $i))
    echo $lineNum
    sed -n "$lineNum"p $javaFile >> ~/Desktop/$1_sql.txt
done

Where $javaFile is a java file and num is an integer.

1
  • 4
    Looks like $num contains a newline character.
    – Mat
    Oct 23, 2014 at 19:30

1 Answer 1

2

Your script is OK. It's the line terminator making it doesn't work, probably. You can check the line terminator with

file YourScriptFile

If it returns something like "...with CRLF line terminators", You can change CRLF to LF line terminator by using

flip -u YourScriptFile

Run the script file again.

P.S. There is a quick and dirty solution to your problem

cut -d $'\n' -s -f ${num},$((num+5))-$((num+max)) $javaFile

-d $'\n' means we are using \n as delimiter and -f ${num},$((num+5))-$((num+max)) means the fields (in this situation, lines) you want. Fields are a list, which can be 1-3, 1,3-10 etc.

Your Answer

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

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