elif
.I'm trying to get rid of hyphenation in string if it has itwhat are you trying to do ?
the script does not make much sense to me
But still, how to check that the string actually has the '-' char followed by "\n" (newline char).sed -e 's/-//g' infile.txt >outfile.txt
sed
uses regular expressions to "check" the string (the part between /-/
). I believe the end of a line is matched with $, so use /-$/
instead.Re-read what SirDice wrote. I often have to re-read a short sentence several times before an explanation actually starts making sense to me. Sometimes, a small detail did not register with me -and turned out to be THE difference between success and failure. An incredibly common pitfall when doing anything computer-related, it got me more times than I care to remember.But still, how to check that the string actually has the '-' char followed by "\n" (newline char).
$ cat mytext.txt
some line of text
other line of text-
more text-
I'm running out of ideas to write
$ cat mytext.txt | sed -e 's/-$//;H;1h;$!d;x;y/\n/ /'
some line of text other line of text more text I'm running out of ideas to write
!d
and interpret it as a history search command. Regardless if you single or double quote the string. dice@williscorto:~/test % cat mytext.txt | sed -e 's/-$//;H;1h;$!d;x;y/\n/ /'
cat mytext.txt | sed -e 's/-$//;H;1h;$df -h;x;y/\n/ /'
sed: 1: "s/-$//;H;1h;$df -h;x;y/ ...": extra characters at the end of d command
$!d
got translated to $df -h
Nice code. I generally prefer to keep it simple, clean, and reusable to solve a specific issue, especially when trying to teach someone.Oh, and I had to this with sh(1) interactively. tcsh(1) will just "eat" that!d
and interpret it as a history search command. Regardless if you single or double quote the string.
Notice how thatCode:dice@williscorto:~/test % cat mytext.txt | sed -e 's/-$//;H;1h;$!d;x;y/\n/ /' cat mytext.txt | sed -e 's/-$//;H;1h;$df -h;x;y/\n/ /' sed: 1: "s/-$//;H;1h;$df -h;x;y/ ...": extra characters at the end of d command
$!d
got translated to$df -h
#!/bin/sh
# Original recepie: [URL]http://www.webupd8.org/2016/03/translate-any-text-you-select-on-your.html[/URL]
tr_id="$(wc -l /tmp/notitrans | sed -e 's/^[ \t]*//' | cut -d ' ' -f1)"
tw=$((tr_id+1))
text="$(xsel -o | perl -pe 's/-\n//g')"
translate="$(wget -U "Mozilla/5.0" -qO - "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=ru&dt=t&q=$(echo $text | sed "s/[\"'<>]//
g")" | sed "s/,,,0]],,.*//g" | awk -F'"' '{print $2}')"
echo "$tw:" "$text" " : " "$translate" >> /tmp/notitrans
I'm gonna quibble with your English spelling here: it's 'recipe', not 'recepie'. Being that anal about spelling helps avoid typos (and potentially specifying incorrect API's or ending up on a squatted domain that was intentionally mis-spelled).# Original recepie: