Hi, if you have to display only the odd lines from the file we can try
let file
$ cat myfile.txt
1
2
3
4
5
6
7
8
9
$ sed -ne '1~2p' myfile.txt
1
3
5
7
9
$ awk '{if (NR%2==1) {print;} }' myfile.txt
1
3
5
7
9
Friday, November 4, 2011
Friday, October 14, 2011
Scatter Gather on linux
Hi,
I have been doing this many times but never blogged, its the scatter gather use to be on dbase days;
This program:
$ cat hello.sh
source e/big.conf
set `date` && export WeekDay=$1 Month=$2 Day=$3 Time=$4 Year=$6
echo Hello $NAME
echo $NO
echo Time: $Time
echo Date: $WeekDay $Month $Day $Year
$ sh hello.sh
Hello SmaLl
2000
Time: 11:24:29
Date: Fri Oct 14 2011
In hello.sh, i am calling the name/value pairs file,
$ cat e/big.conf
Exporting the date o/p to the positional parameters, hey did it in college days.
set `date` && export WeekDay=$1 Month=$2 Day=$3 Time=$4 Year=$6
Here we can have large name value pairs from static file or runtime command and play with it.
I have been doing this many times but never blogged, its the scatter gather use to be on dbase days;
This program:
$ cat hello.sh
source e/big.conf
set `date` && export WeekDay=$1 Month=$2 Day=$3 Time=$4 Year=$6
echo Hello $NAME
echo $NO
echo Time: $Time
echo Date: $WeekDay $Month $Day $Year
$ sh hello.sh
Hello SmaLl
2000
Time: 11:24:29
Date: Fri Oct 14 2011
In hello.sh, i am calling the name/value pairs file,
$ cat e/big.conf
NAME=SmaLl
NO=2000
Exporting the date o/p to the positional parameters, hey did it in college days.
set `date` && export WeekDay=$1 Month=$2 Day=$3 Time=$4 Year=$6
Here we can have large name value pairs from static file or runtime command and play with it.
Wednesday, August 24, 2011
more on date and old date
Hi,
I had to work with epoch dates, that was older than the current, struggled a bit.
check this,
dt2=`date -d "$dt 1 hour ago"`
s1=`date -d "$dt1" +"%s"`
s2=`date -d "$dt2" +"%s"`
echo Now - $dt1
echo
echo "1 Hour Before -- $dt2 : $s2"
echo "Now -- $dt1 : $s1"
put whatever for 1 hour ago as (ago for old, just 1 hour for future, you can have day, minutes)
change dt1 for any date, here its current can be date by -d option
PS:
check good examples in the info pages, i checked this late.. :(
$info date examples
I had to work with epoch dates, that was older than the current, struggled a bit.
check this,
#!/bin/bash
dt1=`date`dt2=`date -d "$dt 1 hour ago"`
s1=`date -d "$dt1" +"%s"`
s2=`date -d "$dt2" +"%s"`
echo Now - $dt1
echo
echo "1 Hour Before -- $dt2 : $s2"
echo "Now -- $dt1 : $s1"
put whatever for 1 hour ago as (ago for old, just 1 hour for future, you can have day, minutes)
change dt1 for any date, here its current can be date by -d option
PS:
check good examples in the info pages, i checked this late.. :(
$info date examples
Tuesday, May 10, 2011
reading from file or stream
check Occurrences of words in file
What if you had to use if frequently.. simple put it in shell program,
and allow it to either read the given file or from the stream, like wc does.
man bash|col -b > bash.txt
$ wc bash.txt
4910 37273 260193 bash.txt
$ cat bash.txt |wc
4910 37273 260193
the below program does it 'occurrences'
$ cat bash.txt | occurrences
2969 the
1501 is
948 to
944 of
868 a
620 and
..
..
What if you had to use if frequently.. simple put it in shell program,
and allow it to either read the given file or from the stream, like wc does.
man bash|col -b > bash.txt
$ wc bash.txt
4910 37273 260193 bash.txt
$ cat bash.txt |wc
4910 37273 260193
the below program does it 'occurrences'
#!/bin/bash
#program: occurrences
file=${1:--}
cat $file | sed -e 's/[^a-zA-Z0-9.]/ /g' | xargs | tr ' ' '\n' | sort | uniq -c | sort -nr -k1,2
cat $file | sed -e 's/[^a-zA-Z0-9.]/ /g' | xargs | tr ' ' '\n' | sort | uniq -c | sort -nr -k1,2
$ cat bash.txt | occurrences
2969 the
1501 is
948 to
944 of
868 a
620 and
..
..
converting man to text
This will give the text output for 'wc' man page
$ man wc |col -b
this man page may not be that big, try 'bash'
$ man bash|col -b
redirect it to a file, dont ask me how.. this is quite helpful, when you open the text page in you favourite editor and search and read the options on 'bash'
its quite big and does lots of things you tried using other commands.
$ man wc |col -b
this man page may not be that big, try 'bash'
$ man bash|col -b
redirect it to a file, dont ask me how.. this is quite helpful, when you open the text page in you favourite editor and search and read the options on 'bash'
its quite big and does lots of things you tried using other commands.
Wednesday, April 27, 2011
more on time zones
converting to UTC from PDT or IST (date needs timezone short form)
$ TZ="UTC" date -d "Wed Apr 27 23:00:00 PDT 2011"
Thu Apr 28 06:00:00 UTC 2011
$ TZ="UTC" date -d "Wed Apr 27 23:00:00 IST 2011"
Wed Apr 27 17:30:00 UTC 2011
$ TZ="UTC" date -d "Wed Apr 27 11:00:00 IST 2011"
Wed Apr 27 05:30:00 UTC 2011
$ TZ="UTC" date -d "Wed Apr 27 11:00:00 PST 2011"
Wed Apr 27 19:00:00 UTC 2011
$ TZ="UTC" date -d "Wed Apr 27 11:00:00 PDT 2011"
Wed Apr 27 18:00:00 UTC 2011
$ TZ="UTC" date -d "Wed Apr 27 23:00:00 PDT 2011"
Thu Apr 28 06:00:00 UTC 2011
$ TZ="UTC" date -d "Wed Apr 27 23:00:00 IST 2011"
Wed Apr 27 17:30:00 UTC 2011
$ TZ="UTC" date -d "Wed Apr 27 11:00:00 IST 2011"
Wed Apr 27 05:30:00 UTC 2011
$ TZ="UTC" date -d "Wed Apr 27 11:00:00 PST 2011"
Wed Apr 27 19:00:00 UTC 2011
$ TZ="UTC" date -d "Wed Apr 27 11:00:00 PDT 2011"
Wed Apr 27 18:00:00 UTC 2011
Tuesday, April 5, 2011
Date for different time zone
Get the right date of other timezone
$ date
Tue Apr 5 12:55:41 IST 2011
$ TZ=UTC date
Tue Apr 5 07:25:47 UTC 2011
$ TZ="America/Los_Angeles" date
Tue Apr 5 00:25:50 PDT 2011
$ TZ="America/New_York" date
Tue Apr 5 03:26:00 EDT 2011
$ TZ="Europe/Paris" date
Tue Apr 5 09:28:28 CEST 2011
$ date
Tue Apr 5 12:58:37 IST 2011
reference:http://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
$ date
Tue Apr 5 12:55:41 IST 2011
$ TZ=UTC date
Tue Apr 5 07:25:47 UTC 2011
$ TZ="America/Los_Angeles" date
Tue Apr 5 00:25:50 PDT 2011
$ TZ="America/New_York" date
Tue Apr 5 03:26:00 EDT 2011
$ TZ="Europe/Paris" date
Tue Apr 5 09:28:28 CEST 2011
$ date
Tue Apr 5 12:58:37 IST 2011
reference:http://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
Subscribe to:
Posts (Atom)