Visit The New, Modern Unix Linux Community

Search Results

Search: Posts Made By: Indra2011
2,395
Posted By Scrutinizer
Try: xargs -n3 < file You can experiment by...
Try:
xargs -n3 < file
You can experiment by varying the number and see what it does.
2,395
Posted By RudiC
Is awk a MUST? Or would e.g. paste do as well?
Is awk a MUST? Or would e.g. paste do as well?
522
Posted By jim mcnamara
csplit filename /ant/ {*} produces a series of...
csplit filename /ant/ {*}
produces a series of files named xx00 xx01 xx02
the /ant/ part is a regular expression.

See csplit --help for more options. I am assuming linux or GNU coreutils on...
1,090
Posted By RudiC
What's your OS and shell?
What's your OS and shell?
1,090
Posted By RavinderSingh13
Hello Indra2011, I haven't seen your second...
Hello Indra2011,

I haven't seen your second command in any of the solutions provided in this thread?
It will NOT give any results as variables named test1, test2, test3 are never having values. ...
1,090
Posted By RavinderSingh13
Hello Indra2011, Not sure what's going on it...
Hello Indra2011,

Not sure what's going on it is working fine for me, could you please try following things.

I- Check if there are any carriage characters are present or not in your Input_file...
1,090
Posted By RavinderSingh13
Hello Indra2011, Good try :b:, a little...
Hello Indra2011,

Good try :b:, a little adjustment to your solution will be, don't change $3 because it will make it's value to variable as OLD3 which will be dangerous on the first line itself...
1,090
Posted By RudiC
Looks like there's a comma too many in the lines...
Looks like there's a comma too many in the lines with missing elements. Assuming this is an error, try
awk '!$1{$1=OLD1} !$2{$2=OLD2} {OLD1=$1; OLD2=$2} 1' FS="," OFS="," file
101,103,1,2...
400
Posted By jim mcnamara
Some shells like bash have a pseudorandom random...
Some shells like bash have a pseudorandom random number generator.
Which is more than adequate to simulate dealing from a deck of cards.

Here is documentation on using the $RANDOM variable to...
865
Posted By Scrutinizer
Shell: while read line; do for i in A B; do...
Shell:
while read line; do
for i in A B; do
echo "${i}_${line}"
done
done < infile
865
Posted By RavinderSingh13
Hello Indra2011, Could you please try...
Hello Indra2011,

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

awk '{print "A_" $0 ORS "B_" $0}' Input_file
Thanks,
R. Singh
4,582
Posted By Scrutinizer
I believe this would combine from the second to...
I believe this would combine from the second to the third field as one sort key.

To achieve evaluating the 2nd and 3rd fields as separate numeric values, I think one would need:
sort -n -k2,2...
4,582
Posted By Don Cragun
According to the standards, the command: sort...
According to the standards, the command:
sort -n -k2 -k3 file
sorts lines in file into increasing order evaluating field 2 and all fields following it as numeric values and if fields 2 to the end...
776
Posted By Don Cragun
I don't know how to be much clearer than the...
I don't know how to be much clearer than the comment I made before on this:
if($1 in A) { # If the value in the 1st field has been seen before
if(!c) c=p # if c has not been set, set it...
776
Posted By MadeInGermany
@Ravinder, caution: (!A[$1]) is true if the...
@Ravinder, caution: (!A[$1]) is true if the contents is 0. And has the side effect that it defines the A[$1] element (having no value).
A pure lookup (!($1 in A)) is often preferrable.

----------...
776
Posted By Scrutinizer
Another one you could try: awk ' { ...
Another one you could try:
awk '
{
if($1 in A) {
if(!c) c=p
}
else
h=h $1 OFS
}
c && !(p%c) {
if(h) print h
print s
h=s=x
}
{
A[$1]...
776
Posted By RavinderSingh13
Hello Indra2011, Could you please try...
Hello Indra2011,

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

awk '{if(!($1 in A)){C[++o]=$1;};++A[$1];B[$1,A[$1]]=$NF;P=P>A[$1]?P:A[$1]}...
1,217
Posted By greet_sed
Hi, Here is without other text utilities: ...
Hi,

Here is without other text utilities:

#!/bin/bash

while read a b c
do
IFS=$','
for i in $b
do
echo $a $i $c
done
IFS=$' '
done < file
1,217
Posted By ctsgnb
Just by replacing any comma with a Field...
Just by replacing any comma with a Field Separator (FS) (here:a space) + last Field of the line ($NF) + Record Separator (RS) (here:line jump) + First field of the line ($1) + Field separator (FS) (...
591
Posted By Don Cragun
The code vgersh99 provided: awk '{printf...
The code vgersh99 provided:
awk '{printf ((FNR>1 && /^[0-9]/)?RS:"" ) $0}END {print""}' myFile
uses the awk utility to run the awk commands:

{printf ((FNR>1 && /^[0-9]/)?RS:"" ) $0} which runs...
591
Posted By vgersh99
that's fine - it should work for this case as...
that's fine - it should work for this case as well.

try it.
684
Posted By pilnet101
Try: awk '($2>=10 && $2<=20) || ($3>=10 &&...
Try:

awk '($2>=10 && $2<=20) || ($3>=10 && $3<=20)' file

The following assumptions have been made based upon your output:
- If $2 OR $3 are within the min/max range, then print the row. Not $2...
705
Posted By Scrutinizer
Try: #!/usr/bin/awk -f BEGIN { ...
Try:

#!/usr/bin/awk -f

BEGIN {
print("X,Y,Z")
}

/^A/ {
sub($1 FS,x)
A[++n]=$0
}

/^B/ {
for (i=2; i<=NF; i++)
B[++m]=$i
}

END {
for(i=1; i<=n; i++)
705
Posted By RudiC
You need to save the A values into a...
You need to save the A values into a two-dimensional array as well as the B values. Then have two nested for loops across either index to get at the value combinations and print.
819
Posted By Aia
awk 'FNR==NR {a[$1,$2]=$0; next}($1,$2) in a...
awk 'FNR==NR {a[$1,$2]=$0; next}($1,$2) in a {print a[$1,$2], $3}' a.txt b.txt > op.txt
Showing results 1 to 25 of 67

 

Featured Tech Videos

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