Search Results

Search: Posts Made By: kevintse
7,884
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,849
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}'...
7,950
Posted By kevintse
awk 'NR>=3 && /red/' infile
awk 'NR>=3 && /red/' infile
3,357
Posted By kevintse
perl:
perl:
1,855
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,332
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...
9,080
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"
3,769
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.
...
3,769
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,422
Posted By kevintse
You'll have to use backticks: ./script.sh >...
You'll have to use backticks:
./script.sh > `date +"%Y%m%d"`
1,102
Posted By kevintse
echo "DATA" | grep "^[DH]"
echo "DATA" | grep "^[DH]"
1,717
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|'
3,158
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]+/, "");...
859
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,699
Posted By kevintse

6,738
Posted By kevintse
Good idea, but this will be better. grep ", *,"...
Good idea, but this will be better.
grep ", *," infile
6,738
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=,
3,572
Posted By kevintse
try this:
try this:
69,250
Posted By kevintse
echo "Youcaneasilydothisbyhighlightingyourcode."...
echo "Youcaneasilydothisbyhighlightingyourcode." | sed 's/\(.\{3\}\)/\1 /g'
4,554
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.
...
17,180
Posted By kevintse
awk -F: '{print $1}' infile
awk -F: '{print $1}' infile
7,275
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...
3,375
Posted By kevintse
Or this: awk -F- '{print $1}' infile
Or this:
awk -F- '{print $1}' infile
3,074
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,777
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

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