Showing posts with label Sed&Awk. Show all posts
Showing posts with label Sed&Awk. Show all posts

Monday, March 26, 2018

makefile: execute a command and grep then awk

CP=cp
LIB_UNIXODBC=/usr/src/tpkgs/unixodbc/2.3.1/linux86w/lib/libodbc.so
RELEASE_DESTDIR=/bld/release/nsr/fb_mssql_linux/linux86w/source


$(CP) $(LIB_UNIXODBC) $(RELEASE_DESTDIR)/ddbda/odbc/$(shell objdump -p $(LIB_UNIXODBC) |grep
'SONAME' |awk -F ' ' '{print $$2}')


which equals to command line:
cp -f /usr/src/tpkgs/unixodbc/2.3.1/linux86w/lib/libodbc.so /bld/release/nsr/fb_mssql_linux/linux86w/source/ddbda/odbc/libodbc.so.2


Note:
1. shell to execute a command in a makefile
2. not like that in bash command line, the grep string is marked with single quotes.
3. there are double '$' in the awk statement.

Monday, May 15, 2017

Modify port number in .xml configuration file

1234

[root@sandbox jetty]# cat a.sh
#!/bin/bash
port=$1

sed -i 's/[0-9]\+<\/Set>/'"${port}"'<\/Set>/g' jetty.xml


Example:
[root@sandbox jetty]# ./a.sh 5678

Monday, January 5, 2015

Problem: sum for each column in a text file(ignoring the first line)

Solution:
cat file |awk -F " " 'function abs(x){return ((x < 0.0) ? -x : x)}NR>1{sum1+=$1; sum2+=abs($2)} END{print sum1;print sum2}'

Example:
$cat file
1000    1000
8       8
2       -2
3       0
7       5
$.my.sh
20
15

Ignore the first line in a text file

Problem:
    ignore the first line in a text file under Linux

Solution:
    1)  cat file |awk 'NR>1{print$0}'
    2)  cat file |sed 1d


Example:
$ cat file
1000    1000
8       8
2       -2
3       0
7       5

$ cat file |sed 1d
8       8
2       -2
3       0
7       5