Search Results

Search: Posts Made By: looney
3,714
Posted By Scrutinizer
Try: awk ' BEGIN { FS=OFS="|" ...
Try:
awk '
BEGIN {
FS=OFS="|"
print "col1|col2"
}

FNR==n+1 {
print $p1, $p2
}
' n=1 p1=1 p2=2 file1 p1=2 p2=3 file2 p1=3 p2=2 file3

col1|col2
a|1
3|C
D|4
3,714
Posted By Aia
awk -v answer42='col1|col2' ' BEGIN { ...
awk -v answer42='col1|col2' '
BEGIN {
FS=OFS="|"
print answer42
}

FNR==universe+1 {
print $mouse1, $mouse2
}
' FS=\| OFS=\| universe=1 mouse1=1 mouse2=2 file1 mouse1=2...
988
Posted By Scrutinizer
Another approach: awk '{A[$1]=$0} $1==40{print...
Another approach:
awk '{A[$1]=$0} $1==40{print A[20] " AND " $2 RS A[30]} $1!~/^[234]0$/' file



---
or
awk '{A[i=$1]=$0; $1=x} i==40{print A[20] " AND" $0 RS A[30]} i!~/^[234]0$/' file


...
892
Posted By Chubler_XL
Try this awk script: awk ' { ...
Try this awk script:

awk '
{
values=split($2,V,";")
sample[NR]=$1
for(i=1;i<=values;i++) {
if(!(V[i] in CI)) {
CI[V[i]]
CH[++col]=V[i]
}
...
6,121
Posted By Don Cragun
Hi looney, Note that the above code changes the...
Hi looney,
Note that the above code changes the first line of input:
Login;Statusto:
Login;Enabled
but the desired output showed that that line was not supposed to be changed.

To meet the...
1,188
Posted By MadeInGermany
I usually prefer if-then-else-fi if [[ -d...
I usually prefer if-then-else-fi
if [[ -d "$dir" ]]; then echo "Dir exists $dir"; else echo "dir $dir doesnot exists"; exit 0; fiand think that multi-line is better readable and maintainable....
1,188
Posted By RudiC
Still not clear what you want. Just...
Still not clear what you want.

Just guessing: [[ -f '$dir/$filename*' ]] does not supply your filename.
man bash:

You could try to use [ ... ]. But, some caveats are to be considered:...
2,038
Posted By RavinderSingh13
Thanks a lot RudiC for this nice script. I know...
Thanks a lot RudiC for this nice script. I know it is some days now for this post but wanted to add explanation here so that everybody could take advantage of this nice code snippet.

awk '
NR ==...
17,961
Posted By Aia
perl # perl binary -M...
perl # perl binary
-M strict # use strict
-M List::Util=sum # use List::Util qw(sum).To know what the subroutine sum is.
-w # use...
1,182
Posted By RavinderSingh13
Hello looney, Could you please go thorugh...
Hello looney,

Could you please go thorugh following and let me know if this helps you.

if ($1+0) sub ($1 FS, _) #### In if condition it is mentioned $1+0, so by adding 0 to $1's value we...
1,182
Posted By RudiC
This seems to cure the failures you quote except...
This seems to cure the failures you quote except for the processing speed - I'm afraid you can't do faster...awk '
NR == FNR {a[$1] = $2
next
}
...
1,838
Posted By RudiC
Should your system allow for multibyte input and...
Should your system allow for multibyte input and output separators, try
awk '!(/phpinfo/ && /hlight/)' RS="\?>\n" ORS="?>\n" file
7,327
Posted By MadeInGermany
Some sed versions do have the \< and \> boundary...
Some sed versions do have the \< and \> boundary anchors; they do not consume a character. And not only allow a /g in one go but also make the substitution easier.
sed 's#\<[0-9]/#0&#g'--
Just...
1,761
Posted By Yoda
awk '!A[$0]++' file
awk '!A[$0]++' file
2,195
Posted By RavinderSingh13
Hello looney, So when you do print xit will...
Hello looney,

So when you do print xit will print actually a NULL value(which is in other words will be a new line only because there is NO value for vriable named x here). But when we do print,...
1,752
Posted By RavinderSingh13
Hello andy391791, Following may help you in...
Hello andy391791,

Following may help you in same.

awk '{gsub("\n[^\n]*/",","); #### gsub, it's an awk's in-built keyword which is used for global substitutions, it's format is...
1,752
Posted By Scrutinizer
Another approach: awk '{for(i=2; i<=NF; i++)...
Another approach:
awk '{for(i=2; i<=NF; i++) sub(".*/",x,$i); sub(OFS,FS)}1' FS='\n' OFS=, RS= ORS='\n\n' file



--edit--
Yet another option:
awk '{gsub("\n[^\n]*/",","); sub(",","\n")}1' RS=...
13,911
Posted By Scrutinizer
sed "s/.*/'&';/" file
sed "s/.*/'&';/" file
1,142
Posted By Don Cragun
The general form of the command: sed -n...
The general form of the command:
sed -n "/$(date '+^%a %b %d')/,\$ s/WARNING: await timed out/&/p"
is:
sed -n "address1,address2 s/pattern/replacement/flags
In this case address1 is a basic...
3,884
Posted By Don Cragun
If you're using awk anyway, why not do it all in...
If you're using awk anyway, why not do it all in awk?
zcat /a/b/c/file.gz |awk 'length > m{m = length}END{print m}'
gets rid of the need for sort, head, and cut.
2,550
Posted By RavinderSingh13
Hello looney, Not completely sure about your...
Hello looney,

Not completely sure about your whole requirement, could you please change pth/"tgt_file_name"CURR_DATE"_"NR%10 to following into your code and let me know how it goes please.

...
2,035
Posted By RudiC
Or awk '{printf "%*.*f\n", FL,...
Or awk '{printf "%*.*f\n", FL, FL-1-length(int($1)), $1}' FL=10 file
234.234000
12.4000000
3456.56780
2,035
Posted By Scrutinizer
Hi, in bash/ksh93/zsh : num=23544.2 ...
Hi, in bash/ksh93/zsh :
num=23544.2
num10=$(printf "%-10s" "$num")
printf "%s\n" "${num10// /0}"

I assumed you mean a value in a variable in a shell script, and that the number length including...
1,709
Posted By Don Cragun
You could also write that so it only evaluates...
You could also write that so it only evaluates field 3 once:
awk '!($3 ? A[$2,$1]++ : A[$1,$2]++)' infile
1,118
Posted By RudiC
Any attempts/ideas/thoughts from your side? ...
Any attempts/ideas/thoughts from your side?

---------- Post updated at 11:33 ---------- Previous update was at 11:11 ----------

Howsoever, tryawk '{print $0 ORS > "file" 2- ($2 ~ /dn:...
Showing results 1 to 25 of 62

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