0

I am trying to run a code in jupyter notebook Python3 see below:

%% bash
rm rvd2.txt
rm rvd22.txt
 rm lsfdout.lsf

    cat wrench.txt | sed 's/[[:space:]]/\n/g' | sed 's/^[ \t]*//' | 
 sed 's/[ \t]*$//' | \
 sed '/^$/d'| tr -cd '[:alnum:] [:space:]' >> rvd2.txt

 awk 'length>3'  < rvd2.txt > rvd22.txt

 cat rvd22.txt | sort | uniq -c | sort -nr | head -n 250 > lsfdout.lsf

The error I get is this,

 File "<ipython-input-33-7c6457f6d2eb>", line 2
  %% bash
   ^
  SyntaxError: invalid syntax

I am totally out of clue why this happens, as a multiline code is supposed to be using double percent sign before bash

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
ambrish dhaka
  • 689
  • 7
  • 27
  • You shouldn't have a space between `%%` and `bash` – Adonis Apr 10 '18 at 14:04
  • I tried this suggestion as well, same error reported with only difference `%%bash` as the stated error. – ambrish dhaka Apr 10 '18 at 14:09
  • I have reached one stage of correction by removing the `%%bash` and putting `!` mark at beginning of each bash code as follows, `!rm rvd2.txt !rm rvd22.txt !rm lsfdout.lsf !cat wrench.txt | sed 's/[[:space:]]/\n/g' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | \ sed '/^$/d'| tr -cd '[:alnum:] [:space:]' >> rvd2.txt !awk 'length>3' < rvd2.txt > rvd22.txt !cat rvd22.txt | sort | uniq -c | sort -nr | head -n 250 > lsfdout.lsf` – ambrish dhaka Apr 10 '18 at 15:11
  • But the above code gives the following error. `sort: write failed: 'standard output': Broken pipe sort: write error` how to resolve this. – ambrish dhaka Apr 10 '18 at 15:13
  • I am able to run the script successfully but this code line needs improvement `!cat rvd22.txt | sort | uniq -c | sort -nr | head -n 250 > lsfdout.lsf` as even though the file created is ok, but can this code be improved to remove the error produced everytime. – ambrish dhaka Apr 10 '18 at 15:21

0 Answers0