Search Results

Search: Posts Made By: kevintse
7,333
Posted By kevintse
Cool, you just changed the output record...
Cool, you just changed the output record separator accordingly.
I am just using the tools, while you are playing with the tools.
That was amazing!
1,528
Posted By kevintse
awk 'BEGIN{OFS="\t"} NR == FNR{a[$0]; next}...
awk 'BEGIN{OFS="\t"}
NR == FNR{a[$0]; next}
FNR == 1{ for(i=1;i<=NF;++i){if($i in a){a[$i]=i}} for(e in a){printf e OFS} printf ORS; next}
{for(i in a){printf $a[i] OFS} printf ORS}'...
6,410
Posted By kevintse
awk 'NR>=3 && /red/' infile
awk 'NR>=3 && /red/' infile
2,546
Posted By kevintse
perl:
perl:
1,624
Posted By kevintse
You probably need unix2dos and dos2unix. ...
You probably need unix2dos and dos2unix.
Windows uses 0x0d0a as newline, while Unix uses 0x0a.
1,188
Posted By kevintse
If you want to list all files matching the...
If you want to list all files matching the pattern under /etl/PDAC/CBA/Supplier/, use the following script:
#!/usr/bin/perl
use strict;
use warnings;
opendir(DIR, "/etl/PDAC/CBA/Supplier/") or...
7,671
Posted By kevintse
You can read multiple fields: read month file; ...
You can read multiple fields:
read month file;
May filename.txt<ENTER>;
grep "$month" "$file"
2,916
Posted By kevintse
OK, I guess you still have more than 2 identical...
OK, I guess you still have more than 2 identical consecutive words spanning multiple lines, and you have to reserve all the newline characters, this can be a challenge, at least with SED.
...
2,916
Posted By kevintse
Fixed, I forgot to add the word boundary(marked...
Fixed, I forgot to add the word boundary(marked as red) for the identical consecutive word:

sed ':f;N;$!bf; s/\b\(.*\)\n\1\b/\1\n/g; s/\b\(.*\)\b\1\b/\1/g'
3,109
Posted By kevintse
You'll have to use backticks: ./script.sh >...
You'll have to use backticks:
./script.sh > `date +"%Y%m%d"`
823
Posted By kevintse
echo "DATA" | grep "^[DH]"
echo "DATA" | grep "^[DH]"
2,710
Posted By kevintse
pbillast's solution won't work as expected when...
pbillast's solution won't work as expected when Name or Country contains more than one word, the following code does:
awk '/^(Name|Age|Country)/{ $1=""; sub(/^[ \t]+/, "");...
1,438
Posted By kevintse
You may stick to grep and cut: echo...
You may stick to grep and cut:
echo "/home/one/two/three/" | grep -Eo '[^/]+/?$' | cut -d / -f1
Or just perl:
echo "/home/one/two/three/" | perl -pe 's|^.+?([^/]+)/?$|$1|'
723
Posted By kevintse
If AWK is an option: gawk 'FNR==NR{a[$0]; next}...
If AWK is an option:
gawk 'FNR==NR{a[$0]; next} {if($0 in a){delete a[$0]}else{++c}} END { print "Count of difference: ", length(a)+c }' data.txt data2.txt
7,015
Posted By kevintse

6,437
Posted By kevintse
Good idea, but this will be better. grep ", *,"...
Good idea, but this will be better.
grep ", *," infile
6,437
Posted By kevintse
awk -F, ' {for(i=1;i<=NF;++i) { s=$i; gsub(/ +/,...
awk -F, ' {for(i=1;i<=NF;++i) { s=$i; gsub(/ +/, "", s); if(s=="") { print; break; }} } ' infile OFS=,
2,706
Posted By kevintse
try this:
try this:
62,947
Posted By kevintse
echo "Youcaneasilydothisbyhighlightingyourcode."...
echo "Youcaneasilydothisbyhighlightingyourcode." | sed 's/\(.\{3\}\)/\1 /g'
15,164
Posted By kevintse
awk -F: '{print $1}' infile
awk -F: '{print $1}' infile
3,505
Posted By kevintse
If you remove the ".*" part from the regex, that...
If you remove the ".*" part from the regex, that means you want to match a line that has only 16 characters, this simply does not match anything, so the original string is output.
...
6,771
Posted By kevintse
There are punctuations in your string, so: awk...
There are punctuations in your string, so:
awk -F"[ ,.]" '{for(i=1;i<=NF;++i) if($i!="")a[$i]} END {for(s in a) print s}' infile
If you insist on using FS, try this, it has the same output as the...
2,978
Posted By kevintse
Or this: awk -F- '{print $1}' infile
Or this:
awk -F- '{print $1}' infile
2,550
Posted By kevintse
try this: awk ' { ++a[$0] } END { for(s in a) {...
try this:
awk ' { ++a[$0] } END { for(s in a) { for(i=1;i<=a[s];++i) { print s, i, a[s] } } } ' inputfile

Note: your input data is assumed to be sorted.
2,457
Posted By kevintse
The AWK way: awk '/^[0-9]+/ { print "63"$0;...
The AWK way:
awk '/^[0-9]+/ { print "63"$0; next } { print }' infile
Showing results 1 to 25 of 27

 

Featured Tech Videos

All times are GMT -4. The time now is 03:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy