Creating a child process in perl
This example fork 10 child processes.It will wait for all child's to finish before exiting.
Output looks like:
class String { public: String (int n);//allocate n bytes to the String object String(const char *p); // initializes object with char *p }Now if you try
String mystring='x';The char 'x' will be converted to int and will call String(int) constructor. But this is not what the user might have intended. So to prevent such conditions, we can define the class's constructor as explicit.
class String { public: explicit String (int n); //allocate n bytes String(const char *p); // initialize sobject with string p }
sed -i '/^$/d' your_fileBut there is also another way to do this:
grep . your_file > dest_fileIn perl also we can acheive this as below:
perl -pi -e 's/^$//g' your_filethe above mentioned perl and sed solutions will do an inplace replacement in the file
perl -pi -e 's/^\s*$//g' your_file
awk '{print $1>"abc"FNR".txt"}' file*file* above should refer to all 40k files.
awk '{x="abc"FNR".txt";print $1>x}' file*
FILE* pipe = popen("your shell command here", "r"); if (pipe) { char buffer[128]; while(!feof(pipe)) { if(fgets(buffer, 128, pipe) != NULL){} } pclose(pipe); buffer[strlen(buffer)-1] = '\0'; }
grep 'abc' *
find . -type f|xargs grep 'abc'
find . -type f -exec grep 'abc' {} \;
llvm
which doesn't have this restriction.java.lang.Object
). #ifdef/#ifndef
type). ::
in Java. It has .
using which we can qualify classes with the namespace they came from. goto
statement in Java.> ls -1 foo* foo-bar-(ab-4529111094).txt foo-bar-foo-bar-(ab-189534).txt foo-bar-foo-bar-bar-(ab-24937932201).txtSo the expected file names would be :
> ls -1 foo* foo-bar-foo-bar-bar.txt foo-bar-foo-bar.txt foo-bar.txtBelow is a simple way to do it.
> ls -1 | nawk '/foo-bar-/{old=$0;gsub(/-\(.*\)/,"",$0);system("mv \""old"\" "$0)}'Explanation:
ls -1Will list all the files in a single column in a directory
nawk '/foo-bar-/The processing is done only for a file names with has foo-bar- as a part of their names.
old=$0initially storing the file name in a variable.
gsub(/-\(.*\)/,"",$0)Removing the undesired part of the file name.
mv \""old"\" "$0This will be expanded to :mv "foo-bar-(ab-4529111094).txt" foo-bar-foo-bar-bar.txt.You might ask why a '"'.because there is possibility that the fine name might consist a space or any other special character(in our case it has '(' ).
system("mv \""old"\" "$0)This will execute on teh command line what ever is there inside the system call.
Tuesday, January 08, 2013 unix 0 Comments
#!/usr/bin/perl
use strict;
use warnings;
print "hello ! world\n";
>temp.pl
hello ! world
>
#this script is just for test
#the shebang
#!/usr/bin/perl
use strict;
use warnings;
print "hello ! world\n";
> temp.pl
use: Command not found.
use: Command not found.
print: Command not found.
>
#!
the rest of the line is interpreted as the executable to run and with the script file available to that program on stdin. (Details vary slightly, but that is the picture).#whatever
? The shell, attempting to fork an executable and being informed by the kernel that it can't execute the program, as a last resort attempts to interpret the file contents as a shell script. Since the shell is not perl, you get a bunch of errors, exactly the same as if you attempted to runshiftwidth
is the primary variable that controls indentation.>> Indent line by shiftwidth spaces
<< De-indent line by shiftwidth spaces
5>> Indent 5 lines
5== Re-indent 5 lines
>% Increase indent of a braced or bracketed block (place cursor on brace first)
=% Reindent a braced or bracketed block (cursor on brace)
<% Decrease indent of a braced or bracketed block (cursor on brace)
]p Paste text, aligning indentation with surroundings
=i{ Re-indent the 'inner block', i.e. the contents of the block
=a{ Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block
>i{ Increase inner block indent
<i{ Decrease inner block indent
{
with }
or B
, e.g. =iB
is a valid block indent command. Take a look at "Indent a Code Block" for a nice example to try these commands out on.. Repeat last command
, so indentation commands can be easily and conveniently repeated.gg=G Re-indent entire buffer
You can extend this idea to multiple files:" Re-indent all your c source code:
:args *.c
:argdo normal gg=G
:wall
Or multiple buffers:" Re-indent all open buffers:
:bufdo normal gg=G:wall
Vjj> Visually mark and then indent 3 lines
CTRL-T insert indent at start of line
CTRL-D remove indent at start of line
0 CTRL-D remove all indentation from line
:< and :> Given a range, apply indentation e.g.
:4,8> indent lines 4 to 8, inclusive
ma Mark top of block to indent as marker 'a'
...move cursor to end location>'a Indent from marker 'a' to current location
set expandtab "Use softtabstop spaces instead of tab characters for indentation
set shiftwidth=4 "Indent by 4 spaces when using >>, <<, == etc.
set softtabstop=4 "Indent by 4 spaces when pressing <TAB>
set autoindent "Keep indentation from previous line
set smartindent "Automatically inserts indentation in some cases
set cindent "Like smartindent, but stricter and more customisable
Vim has intelligent indentation based on filetype. Try adding this to your .vimrc:if has ("autocmd")
" File type detection. Indent based on filetype. Recommended.
filetype plugin indent on
endif
Friday, January 04, 2013 perl 1 Comments
/abc/123_1/1tvd/fiel.txt /abc/123 r/1tvd/fie2l.txt /abc/123 a/1tvd/fie3l.txt /abc xyz/123/1tvd/fie4l.txtand some times the spaces create a lot of problems while we use those configuration files.
/"abc xyz"/123/1tvd/fie4l.txtBut how do we do it across the complete file?
perl -F"/" -ane 'foreach (@F) {if(/ /){$_="\"".$_."\"";}} print join "/",@F;' config_fileBut yes there can be other ways too like in awk.
Thursday, January 03, 2013 awk , bash , shell variable , shell-script 0 Comments
Thursday, January 03, 2013 perl 0 Comments
Wednesday, January 02, 2013 join 3 Comments
0 comments: