delete all lines before string match including matching line
sed -i '1,//d' $FILENAME
delete all lines after string match including matching line
sed -i '//,$d' $FILENAME
-i option to put changes back into source file
Saturday, March 31, 2012
Friday, March 30, 2012
error while loading shared libraries linux ldd
when you run a binary and get this kind of error, try this command:
ldd
this will show out put as
bin]# ldd /usr/bin/curl
linux-gate.so.1 => not found
libcurl.so.4 => /usr/lib/libcurl.so.4 (0x00dd0000)
libz.so.1 => /usr/lib/libz.so.1 (0x00be6000)
libssh2.so.1 => /usr/lib/libssh2.so.1 (0x00110000)
libc.so.6 => /lib/libc.so.6 (0x00a41000)
librt.so.1 => /lib/librt.so.1 (0x00415000)
try to build again by linking the missing library file.
ldd
this will show out put as
bin]# ldd /usr/bin/curl
linux-gate.so.1 => not found
libcurl.so.4 => /usr/lib/libcurl.so.4 (0x00dd0000)
libz.so.1 => /usr/lib/libz.so.1 (0x00be6000)
libssh2.so.1 => /usr/lib/libssh2.so.1 (0x00110000)
libc.so.6 => /lib/libc.so.6 (0x00a41000)
librt.so.1 => /lib/librt.so.1 (0x00415000)
try to build again by linking the missing library file.
Thursday, March 29, 2012
shell script redirect
There are 3 file descriptors, stdin, stdout and stderr (std=standard).
Basically you can:
Basically you can:
- redirect stdout to a file
- redirect stderr to a file
- redirect stdout to a stderr
- redirect stderr to a stdout
- redirect stderr and stdout to a file
- redirect stderr and stdout to stdout
- redirect stderr and stdout to stderr
Sample: stdout 2 file
This will cause the ouput of a program to be written to a file. ls -l > ls-l.txt
Here, a file called 'ls-l.txt' will be created and it will contain what you would see on the screen if you type the command 'ls -l' and execute it. Sample: stderr 2 file
This will cause the stderr ouput of a program to be written to a file. grep da * 2> grep-errors.txt
Here, a file called 'grep-errors.txt' will be created and it will contain what you would see the stderr portion of the output of the 'grep da *' command. Sample: stdout 2 stderr
This will cause the stderr ouput of a program to be written to the same filedescriptor than stdout. grep da * 1>&2
Here, the stdout portion of the command is sent to stderr, you may notice that in differen ways. Sample: stderr 2 stdout
This will cause the stderr ouput of a program to be written to the same filedescriptor than stdout. grep * 2>&1
Here, the stderr portion of the command is sent to stdout, if you pipe to less, you'll see that lines that normally 'dissapear' (as they are written to stderr) are being kept now (because they're on stdout). Sample: stderr and stdout 2 file
This will place every output of a program to a file. This is suitable sometimes for cron entries, if you want a command to pass in absolute silence. rm -f $(find / -name core) &> /dev/null
This (thinking on the cron entry) will delete every file called 'core' in any directory. Notice that you should be pretty sure of what a command is doing if you are going to wipe it's output.
shell script: to execute a string in variable as shell command
temp="ip=1.1.1.$p"
i wanted to extract ip address into a variable
solution:
eval ${temp}
myVar=$ip
i wanted to extract ip address into a variable
solution:
eval ${temp}
myVar=$ip
Wednesday, March 28, 2012
ubuntu upgrade: restore applications collections
you can save a list of installed packages on the old machine with the command
dpkg --get-selections > ~/packages
and then restore it on the new one with sudo dpkg --set-selections < ~/packages && apt-get dselect-upgrade
.
Subscribe to:
Posts (Atom)