Why is case insensitive search and replace not working in Solaris sed? [closed] - sed

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I tried the following commands in Solaris sed for case insensitive find and replace
sed s/TOFIND/REPLACE/gi fileName
sed s/TOFIND/REPLACE/gi fileName
/usr/xpg4/bin/sed s/TOFIND/REPLACE/gi fileName
/usr/xpg4/bin/sed s/TOFIND/REPLACE/gi fileName
but none of the ways worked. I got command garbled error for all. Is there no support for case insensitive search in Solaris sed?

i is a non standard GNU sed extension.
You can use GNU sed if installed. It might be in /usr/sfw/bin/gsed or /usr/gnu/bin/sed depending on the version.
Otherwise, the standard way is
sed 's/[Tt][Oo][Ff][Ii][Nn][Dd]/REPLACE/g' fileName
You might automatize the process that way:
pattern="tofind"
sed "s/$(printf "%s" "$pattern"|sed 's/./\[\U&\L&\]/g')/REPLACE/g" fileName

another alternative is to replace each aphabetic char of the search pattern by his equivalent [sC] like this: by [tT][hH][iI][sS]: (with a previous sed/awk on pattern to be generic)
printf "%s\n" "SearchPattern" | sed 's/[aA]/[aA]/g;s[bB]/[bB]/g; ..... ;s/[zZ]/[zZ]/g' | read -r CaseSearchPattern
/usr/xpg4/bin/sed "s/${CaseSearchPattern}/REPLACE/g" fileName
just add a second test eventually (and corrective action) if some special char like \ are in the content due to "" shell interpretation arround the sed action

Related

ANSI sequence to change terminal name [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I use a bash script (konsole-name.sh) to change a terminal name, like this:
#!/usr/bin/bash
echo -en "\e]30;$1\a"
and I wanted to use the same method from a perl script that I use to check the GPU temperature, so that it updates periodically the window title.
Yet I didnt find a way.
I tried both this:
$comm='echo -en "\e]30;T=$t\a"';
`$comm`;
and this, using my bash script:
$comm="konsole-name.sh T=$t";
`$comm`;
there is some way to do it?
The console escape sequences work by printing text to the terminal. In your case, the backticks gobble up the output of the script.
Most likely you just want print "\e]30;$1\a"; from within Perl:
my $title = "Fancy terminal title";
print "\e]30;${title}\a";

Double exclamation in fish shell [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
In zsh, I can execute them.
$ sleep 1
$ echo !$ # !$ equals 1
$ echo !! # !! equals sleep 1
But I can't execute them in fish shell.
Could tell me why and where the zsh documentation is?
This is history expansion, which has a lot more to it then those simple examples.
Fish supports none of it (and probably never will). The usual workaround is to use keybindings. By default, alt-up and alt-down should go through the history token-wise, so you can press alt-up once to get what is effectively !$.
If you wish to prepend something to a command from history, recall that command, go to the beginning (e.g. with ctrl-a) and insert what you want.
Other possibilities are functions to bind e.g. !! to something to insert the previous command or to make a command called !!.
This is still discussed in fish issue #288, though concensus seems to be against adding history expansion.

What is a good way to count source lines of code (SLOC) in a CoffeeScript project? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Is there a common way of counting source lines of code (SLOC) in a CoffeeScript project?
I'm hoping for something that will traverse all of the directories in my project during the count. I found a few projects online but they seemed kind of overkill for the task. I would love a simple utility or even just some command-line-fu.
If you're on UNIX, I would go with the wc tool. I usually use wc -l *.coffee */*.coffee etc. because it is easy to remember. However, a recursive version would be
wc -l `find <proj-dir> -type f | grep \.coffee$`
which runs the find command, which recursively lists files of type f, or normal files, fed into the grep, which filters down to just Coffeescript files, and the output of that is used as the command line arguments to wc (-l signals a line count).
Edit: Now we don't want to count blank or comment lines (we're only catching single-line comments here). We lose the per-file counts, but here goes:
cat `find <proj-dir> -type f | grep \.coffee$` | sed '/^\s*#/d;/^\s*$/d' | wc -l
We find the Coffeescript files, and then cat them. Then, sed strips out lines that consist of only whitespace or have whitespace followed by a #. Finally, our friend wc counts the remaining lines.
This will do what you want: https://github.com/blackducksw/ohcount
It correctly excludes comments and blank lines and also supports many other languages.

Find and replace text in a 47GB large file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have to do some find and replace tasks on a rather big file , about 47 GB in size .
Does anybody know how to do this ? I tried using services like TextCrawler , EditpadLite and more but nothing supports this large a file .
I'm assuming this can be done via the commandline .
Do you have an idea how this can be accomplished ?
Sed (stream editor for filtering and transforming text) is your friend.
sed -i 's/old text/new text/g' file
Sed performs text transformations in a single pass.
I use FART - Find And Replace Text by Lionello Lunesu.
It works very well on Windows Seven x64.
You can find and replace the text using this command:
fart -c big_filename.txt "find_this_text" "replace_to_this"
github
On Unix or Mac:
sed 's/oldstring/newstring/g' oldfile.txt > newfile.txt
fast and easy...
I solved the problem usig, before, split to reduce the large file in smalls with 100 MB each.
If you are using a Unix like system then you can use cat | sed to do this
cat hosted_domains.txt | sed s/com/net/g
Example replaces com with net in a list of domain names and then you can pipe the output to a file.
For me none of the tools suggested here work well. Textcrawler ate all my computer's memory, SED didn't work at all, Editpad complained about memory...
The solution is: create your own script in python, perl or even C++.
Or use the tool PowerGrep, this is the easiest and fastest option.
I have't tried fart, it's only command line and maybe not very friendly.
Some hex editor, such as Ultraedit also work well.
I used
sed 's/[nN]//g' oldfile.fasta > newfile.fasta
to replace all the instances of n's in my 7Gb file.
If I omitted the > newfile.fasta aspect it took ages as it scrolled up the screen showing me every line of the file.
With the > newfile it ran it in a matter of seconds on an ubuntu server

Searching through Stackoverflow.com from the commandline/bash [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
As the title says i am looking for a way to search through stackoverflow.com using only the command line specifically bash in linux.
Things I need to accomplish :
I just need to get the top 10 answers for my question or even top 5.
Plain Text Output , i.e. strip
HTML out if possible.
Also I would prefer if you didnt give a answer that required elinks or something similar.
here's a rough script to run from command line that does the job
wget 'http://stackoverflow.com/feeds/tag?tagnames=command-line&sort=newest' -qO - | perl -nle ' print $1 if /\<title[^>]+\>([^<]*)/;'|head
It grabs RSS output for a given tag (command-line here) and sort of parses it.
To be done properly one would probably want to parse XML in a better way or use some perl rss parser.