I'm trying to write a sed command to increment the below release number in a file.txt. Please help me out.
versionAndDate: 'Release: 1.3
I want the output to be incremental to below value:
versionAndDate: 'Release: 1.4.1
versionAndDate: 'Release: 1.4.2
versionAndDate: 'Release: 1.4.3
versionAndDate: 'Release: 1.4.4
Using sed
$ cat input_file
versionAndDate: 'Release: 1.3
$ cat chg_ver.sh
#!/usr/bin/env bash
max_version=4
for ((i=1; i<=max_version; i++)); do
sed "s/\(.*: \).*/\11.4.$i/" input_file >> output_file
done
$ cat output_file
versionAndDate: 'Release: 1.4.1
versionAndDate: 'Release: 1.4.2
versionAndDate: 'Release: 1.4.3
versionAndDate: 'Release: 1.4.4
Using awk
$ awk -v max_version=4 '{sub(/1.3/,"1.4.");for (i=1; i<=max_version; i++) print $0 i}' input_file
versionAndDate: 'Release: 1.4.1
versionAndDate: 'Release: 1.4.2
versionAndDate: 'Release: 1.4.3
versionAndDate: 'Release: 1.4.4
Related
I am trying to run the command in kdb but it does not work. I knew it may be associated with some special character and I am trying to put the [] to escape but still does not work.
system "awk '/^Mem/ {print $2}' <(free -m)"
I tried
system "awk '/[^]Mem/ {print $2}' <(free -m)" - not working
Another solution just requires a rearrangement of your expression:
q)system"free -m | awk '/^Mem/ {print $2}'"
"25408"
EDIT:
The reason why your expression is failing from q is because of the shell being used. This answer explains the difference between shebang and dash shells. I've added a little test to showcase the difference.
coneill5#LPTP1893: [~] $ cat test.sh
#!/bin/bash
awk '/^Mem/ {print $2}' <(free -m)
coneill5#LPTP1893: [~] $ cat test1.sh
#!/bin/sh
awk '/^Mem/ {print $2}' <(free -m)
coneill5#LPTP1893: [~] $ ./test.sh
25408
coneill5#LPTP1893: [~] $ ./test1.sh
./test1.sh: 2: Syntax error: "(" unexpected
You can avoid a system call as kdb+ can return the physical memory available using .Q.w[]
q)floor (.Q.w[]`mphy)%1024 xexp 2
28072
\\
$ awk '/^Mem/ {print $2}' <(free -m)
28072
Using the following command what modifications need to be made to get frame.time as epoch in tshark?
tshark -T fields -n -r btle.pcap -E separator=, -e frame.time -e btle_rf.access_address_offenses -e btle_rf.channel -e btle_rf.flags -e btle_rf.flags.access_address_offenses_valid -e btle_rf.flags.channel_aliased -e btle_rf.flags.crc_checked -e btle_rf.flags.crc_valid -e btle_rf.flags.decrypted -e btle_rf.flags.dewhitened -e btle_rf.flags.mic_checked -e btle_rf.flags.mic_valid -e btle_rf.flags.noise_dbm_valid -e btle_rf.flags.reference_access_address_valid -e btle_rf.flags.rfu.1 -e btle_rf.flags.rfu.2 -e btle_rf.flags.signal_dbm_valid -e btle_rf.noise_dbm -e btle_rf.reference_access_address -e btle_rf.signal_dbm -e btle_rf.signed_byte_unused -e btle_rf.unsigned_byte_unused -e btle_rf.word_unused>btle.csv
As long as you are running Wireshark 1.4.0 or later, you can try changing -e frame.time to -e frame.time_epoch. If you're running an older version of Wireshark, then I might suggest upgrading to a newer version.
With the latest stable version of Wireshark (2.2.7 as of this writing), all frame filters are documented in View -> Internals -> Supported Protocols -> Frame -> ... and you can always reference the online Display Filter Reference page as well.
When I want to provide directory to include modules I write:
perl -Ilib -Isome/dir script.pl
Should I include archname directory too or is that scanned automatically?
from Makefile:
{APP_ROOT}/local/lib/perl5/${shell perl -MConfig -e 'print $$Config{archname}'}
UPD
perl -V output:
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0/x86_64-linux
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0
archname is included in #INC by default if it exists:
perl -MConfig -E 'say $_ for ($Config{archname}, #INC)'
x86_64-linux
/home/user/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.1/x86_64-linux
/home/user/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.1
/home/user/perl5/perlbrew/perls/perl-5.24.1/lib/5.24.1/x86_64-linux
/home/user/perl5/perlbrew/perls/perl-5.24.1/lib/5.24.1
UPD
It will be added if it exists:
perl -Isomedir -e 'local $"="\n"; print "#INC"'
somedir
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0/x86_64-linux
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0
mkdir -p somedir/x86_64-linux
perl -Isomedir -e 'local $"="\n"; print "#INC"'
somedir/x86_64-linux
somedir
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0/x86_64-linux
/home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0
Yes, if it exists, the arch sub directory will be added to #INC when you add the parent non-arch directory.
Baseline:
$ perl -E'say for #INC' | wc -l
5
Add via -I:
$ perl -Ilib -E'say for #INC' | head -n -5
lib/5.24.0/x86_64-linux-thread-multi
lib/5.24.0
lib
Add via PERL5LIB:
$ PERL5LIB=lib perl -E'say for #INC' | head -n -5
lib/5.24.0/x86_64-linux-thread-multi
lib/5.24.0
lib
Add via lib.pm:
$ perl -E'use lib qw( lib ); say for #INC' | head -n -5
lib/5.24.0/x86_64-linux-thread-multi
lib/5.24.0
lib
Add via mylib.pm:
$ perl -E'use mylib; say for #INC' | head -n -5
/.../lib/5.24.0/x86_64-linux-thread-multi
/.../lib/5.24.0
/.../lib
It doesn't add them if you add directly to #INC:
$ perl -E'unshift #INC, "lib"; say for #INC' | head -n -5
lib
I am trying with the below options
1.copied the data i need in text from out put of
ps ax -o rss,command | sort -nr | head -n 10
2.But this output contains extract like below
856232 /usr/java/jdk1.7.0/bin/java -Djava.util.logging.config.file=/data/vmware/server/xxxxx/conf/logging.properties -XX:MaxPermSize=512m -Xmx1024m -Xms1024m -XX:PermSize=256m -Xss256k -
but i need the string only after /data/vmware/server ie xxxxx.
i tried sed and awk but not getting intended ones.
You could Use grep.
ps ax -o rss,command | sort -nr | head -n 10 | grep -oP 'data/vmware/server/\K[^/]*'
Example:
$ echo '856232 /usr/java/jdk1.7.0/bin/java -Djava.util.logging.config.file=/data/vmware/server/xxxxx/conf/logging.properties -XX:MaxPermSize=512m -Xmx1024m -Xms1024m -XX:PermSize=256m -Xss256k -' | grep -oP 'data/vmware/server/\K[^/]*'
xxxxx
OR
sed.
$ echo '856232 /usr/java/jdk1.7.0/bin/java -Djava.util.logging.config.file=/data/vmware/server/xxxxx/conf/logging.properties -XX:MaxPermSize=512m -Xmx1024m -Xms1024m -XX:PermSize=256m -Xss256k -' | sed 's~.*data/vmware/server/\([^/]*\).*~\1~'
xxxxx
My sed attempts on RHEL 6.3:
$ export LC_ALL=fr_FR.utf-8
$ sed 's/ \([a-zA-Zé]\)\([^ ]*\) /[\u\1\L\2\E] /g' <<< " hélène NOËL étienne "
hélène NOËL étienne
$ export LC_ALL=C
$ sed 's/ \([a-zA-Zé]\)\([^ ]*\) /[\u\1\L\2\E] /g' <<< " hélène NOËL étienne "
[Hÿlÿne] [Noÿl] [ÿtienne]
$ sed --version
GNU sed version 4.2.1
[...]
Is sed able to output the following?
[Hélène] [Noël] [Étienne]
is this ok for you?
kent$ echo " hélène NOËL étienne "|sed -r 's/(\S)(\S+)/[\U\1\L\2]/g'
[Hélène] [Noël] [Étienne]
my sed version is abit different from yours, but I think the line should run there too:
kent$ sed --version |head -1
sed (GNU sed) 4.2.2
added my locale settings, you may want to know:
kent$ echo $LANG
en_US.utf8
kent$ locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
Kent's answer did not solve my issue but I have not provided him all my constraints. My csv input file is like:
sfou;STéphane Foù - stephane.fou#example.com;;
fbar;frédéric bâr - frederic.bar#example.com;;
hnoel;Hélène NOËL - helene.noel#example.com;;
The sed script shall capitalize the names only:
sfou;Stéphane Foù - stephane.fou#example.com;;
8945;Frédéric Bâr - frederic.bar#example.com;;
hnoel;Hélène Noêl - helene.noel#example.com;;
Based on Kent's help, I successfully passed this script:
LC_ALL=fr_FR sed -r 's/(\w)(\w*) /\U\1\L\2 /g' test.cvs
Other locales do not give the right result:
$ LANG=fr_FR.utf8 LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou#example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar#example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel#example.com;;
$ LANG=C LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou#example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar#example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel#example.com;;
$ LANG=en_US.utf8 LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou#example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar#example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel#example.com;;
Locales en_USand fr_FR (without .utf8) are OK:
$ LANG=en_US LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;[Stéphane] [Foù] - stephane.fou#example.com;;
fbar;[Frédéric] [Bâr] - frederic.bar#example.com;;
hnoel;[Hélène] [Noël] - helene.noel#example.com;;
$ LANG=fr_FR LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;[Stéphane] [Foù] - stephane.fou#example.com;;
fbar;[Frédéric] [Bâr] - frederic.bar#example.com;;
hnoel;[Hélène] [Noël] - helene.noel#example.com;;
Note: I have discovered \w from CodeGnome's links.