Search Results

Search: Posts Made By: lucasvs
1,662
Posted By Don Cragun
No. With my script you need the END clause to...
No. With my script you need the END clause to print the trailing <newline>; with spacebar's script you need the END clause to print the entire last line.
Until you hit EOF, you don't know that...
1,662
Posted By spacebar
Try this: awk '/^1_/{if (x)print...
Try this:
awk '/^1_/{if (x)print x;x="";}{x=(!x)?$0"|":x$0;}END{print x;}'
1,314
Posted By Scrutinizer
FILENAME is a built-in variable but it would not...
FILENAME is a built-in variable but it would not be useful here, as it contains the name of the current input file, in this case "input.tab" ..
5,477
Posted By elixir_sinari
Try awk ' BEGIN{OFS=FS="|"} { ...
Try


awk '
BEGIN{OFS=FS="|"}
{
if(NF>max) max=NF
for(i=1;i<=NF;i++)
{
start=match(a[i],$i)
if(start && substr(a[i],(start+RLENGTH),1) ~ /^[,]*$/)
continue
if(a[i])
...
5,477
Posted By elixir_sinari
Try this: awk -F\| 'BEGIN{OFS=FS}...
Try this:

awk -F\| 'BEGIN{OFS=FS} {start=match(a[$1],$2);if(start && substr(a[$1],(start+RLENGTH),1) ~ /^[,]*$/) next; if(a[$1]) a[$1]=a[$1]","$2; else a[$1]=$2} END{for(i in a) print i,a[i]}' file
3,320
Posted By Scrutinizer
Try: #!/usr/bin/awk -f BEGIN{FS=OFS="|"} ...
Try:
#!/usr/bin/awk -f

BEGIN{FS=OFS="|"}

function convert (n, v,w,x,y,r1,r10,r100,r1000){
split("I II III IV V VI VII VIII IX",r1," ")
split("X XX XXX XL L LX LXX LXXX XC",r10," ")
...
4,545
Posted By agama
I guess you have your reasons, but I don't see...
I guess you have your reasons, but I don't see the point of an array of sequential numbers.


awk '
BEGIN {
for( i = 1; i <= 10000; i++ )
numbers[i] = i;
}
4,692
Posted By Scrutinizer
You would need to do something like this to shift...
You would need to do something like this to shift the fields:
awk '{for(i=1; i<=NF; i++) if($i=="") for(j=i;j<=NF;j++)$j=$(j+1)}1' FS=\| OFS=\| infile
output:
1|2|3|4|5|6||
But that still leaves...
20,778
Posted By CarloM
Carlo@CRM-MT4 ~ $ echo "||AAAA 1 2.; AAAA...
Carlo@CRM-MT4 ~
$ echo "||AAAA 1 2.; AAAA 3.|AAAA 5 6.||" | awk '{print gensub (/([^[:blank:]]+[[:blank:]]+[[:digit:]]+[[:blank:]]+[[:digit:]]+)[^.;\|]*/,"\\1","g")}'
||AAAA 1 2.; AAAA 3.|AAAA 5...
6,274
Posted By complex.invoke
awk -F'|' '{for(i=3; i<=NF; ++i) print...
awk -F'|' '{for(i=3; i<=NF; ++i) print $1FS$2FS$i}'
20,778
Posted By CarloM
Well, they worked on your original example :p. ...
Well, they worked on your original example :p.

EDIT:
Try:
Carlo@CRM-MT4 ~
$ echo "AAAA 1 2 f45 iop 234-RT.; AAAA 123 456 gf kuygb 2iuygb.; AAAA 678 89 wer4k lh8." |
> awk '{print gensub...
7,467
Posted By balajesuri
awk -F'|' '{print $0"|"$2}' inputfile
awk -F'|' '{print $0"|"$2}' inputfile
2,120
Posted By Scrutinizer
There is one closing brace missing. It may be...
There is one closing brace missing. It may be that your input file differs from your sample, for example, when it contains some tabs instead of spaces. What happens when you cut and paste your...
8,280
Posted By balajesuri
This will check for the largest length in every...
This will check for the largest length in every column and will space accordingly.

perl -F'\t' -lane '
BEGIN {
open I, "< inputfile";
for (<I>) {
chomp;
@x = split...
8,280
Posted By itkamaraj
nawk -F"\t"...
nawk -F"\t" 'BEGIN{b=0}{for(i=1;i<=NF;i++){a=length($i);if(a>b)b=a;}}END{print b}' input.txt
the above awk will give the longest field in your file.

after that you can pass that value to awk...
1,807
Posted By balajesuri
Yes, you can start with perl -F'\t' -lane '.....
Yes, you can start with perl -F'\t' -lane '.....
1,807
Posted By balajesuri
perl -lane '@x=split /,/,$F[1]; print...
perl -lane '@x=split /,/,$F[1]; print "$F[0]\t$_\t$F[2]" for(@x)' inputfile
1,807
Posted By bartus11
Try: awk -F"\t" -vOFS="\t"...
Try: awk -F"\t" -vOFS="\t" '{n=split($2,a,",");for (i=1;i<=n;i++) print $1,a[i],$3}' file
4,850
Posted By Scrutinizer
the join command concatenates, so: print join...
the join command concatenates, so:
print join ("\t", $-[1]+1 . "-" . $+[1] , @F )
4,850
Posted By Scrutinizer
Try: perl -F\\t -lane 'if ($F[5] =~...
Try:
perl -F\\t -lane 'if ($F[5] =~ s/.*?([13]{1,5}tomatoes[13]{1,5}).*/$1/p) {print join ("\t", @F, $-[1]+1 . "-" . $+[1] )}' infile
4,850
Posted By Scrutinizer
You are selecting on the sixth column instead of...
You are selecting on the sixth column instead of the second column in the example of the starting post, so then you need to replace F[1] with F[5] and are these fields tab separated? Slight...
4,850
Posted By balajesuri
awk splits the line into fields based on...
awk splits the line into fields based on whitespaces by default. So $2 is not "bb11 toma toes 111b bbbbb" but just "bb11". Tell awk to split fields based on tab '\t' and then $2 would be what you...
4,812
Posted By itkamaraj
In the MAC OSX, can you try the below sed ...
In the MAC OSX, can you try the below sed


sed "s/[[:<:]]$a[[:>:]]/$b/g"
4,812
Posted By itkamaraj
if you use single quote in the sed ' then,...
if you use single quote in the sed '

then, it will not evaluate the $a and $b values.

so, it search for $a and replce it to $b
8,900
Posted By ctsgnb
ls -1
ls -1
Showing results 1 to 25 of 29

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