Search Results

Search: Posts Made By: mira
946
Posted By Corona688
awk ' # If a line is ###, forget old values and...
awk '
# If a line is ###, forget old values and print it, then get the next line
/#/ { for(N=2; N<=4; N++) delete A[N] ; print ; next }
# Loop over fields 2 through 4
{ for(N=2; N<=4;...
946
Posted By junior-helper
Far from being an awk expert, but I managed to...
Far from being an awk expert, but I managed to patch following together:
awk '$0 ~ /^#/ {print}
NF==4 {f3=$3;f4=$4;print $0}
NF==2 {print $0" "f3" "f4}' input
Explanation:
$0 ~ /^#/...
946
Posted By Corona688
awk '/#/ { for(N=2; N<=4; N++) delete A[N] ;...
awk '/#/ { for(N=2; N<=4; N++) delete A[N] ; print ; next }
{ for(N=2; N<=4; N++)
{
if($N) { A[N]=$N }
else if(N in A) $N=A[N]
}
}...
3,294
Posted By shamrock
It gives correct output on aix/hpux but when i...
It gives correct output on aix/hpux but when i ran it on redhat it didnt which is strange...i will dig into it and see why its happening...perhaps a bug in gnu's awk.

---------- Post updated at...
3,294
Posted By shamrock
Not sure how this solution is going to pan out...
Not sure how this solution is going to pan out because sorting file1 and file2 still wont lineup the records for a match...unless you provide the script to show how it works as i am unable to...
1,868
Posted By radoulov
awk 'NR == FNR { for (i = 1; ++i <= NF;) ...
awk 'NR == FNR {
for (i = 1; ++i <= NF;)
k[$1, $i]
next
}
{
split(x, ok)
for (i = 1; ++i <= NF;) {
if (($1, $i) in k)
ok[$1] = ok[$1] ? ok[$1] FS $i : $i
...
1,868
Posted By Shell_Life
Here is one way of doing it: #!/usr/bin/ksh ...
Here is one way of doing it:

#!/usr/bin/ksh
typeset -i mCnt
while read mLine
do
mOutLine=""
for mFld in ${mLine}
do
if [[ "${mOutLine}" = "" ]]; then
mOutLine=${mFld}
...
4,473
Posted By drl
Hi. With standard utilities: ...
Hi.

With standard utilities:
#!/usr/bin/env bash

# @(#) s1 Demonstrate extraction of random number of columns.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
pe()...
4,473
Posted By Corona688
What languages do you have available? I'm...
What languages do you have available? I'm pondering a solution in C.

---------- Post updated at 01:27 PM ---------- Previous update was at 12:20 PM ----------

/**
* rc.c picks random columns...
4,473
Posted By drl
Hi, mira. Providing an example would help. ...
Hi, mira.

Providing an example would help.

Given this simple model of data in "row,column" notation:
1,1 1,2 1,3 1,4 1,5 1,6 1,7 1,8 1,9 1,10
2,1 2,2 2,3 2,4 2,5 2,6 2,7 2,8 2,9 2,10
3,1...
4,473
Posted By kurumi
Ruby(1.9.1+) f=open("file") ...
Ruby(1.9.1+)

f=open("file")
numcols=f.readline.split.size
cols=(1..numcols).to_a.sample(4)
while not f.eof?
line=f.gets.split
cols.each{|x| printf "%s " , line[x-1]}
puts
end...
4,473
Posted By ahamed101
Actually it is not very clear lets say you...
Actually it is not very clear

lets say you give n=100, you want to extract first 100 columns from all the rows.

regards,
Ahamed

---------- Post updated at 02:12 AM ---------- Previous...
2,683
Posted By mirni
a[$1]=($1 in a)?a[$1] OFS $3:$3 checks whether...
a[$1]=($1 in a)?a[$1] OFS $3:$3
checks whether first field ($1) is present in array 'a'; if yes, it appends the third column to it; if not, assign third column.
It's a ternary operator, just like...
4,473
Posted By Shell_Life
You can use the "cut" command - the default...
You can use the "cut" command - the default delimiter is horizontal tab:
cut -fn Inp_File

Where "n" is the column number which can be of any length, including zero.
4,473
Posted By Corona688
Just one line of thousands of columns? If...
Just one line of thousands of columns?

If you have or can use the rl utility, it is quite fast indeed:

rl -d $'\t' -c 32 tabseperatedfile
2,683
Posted By vgersh99
Assuming the values of the second field repeat in...
Assuming the values of the second field repeat in the same order as $1 changes...

nawk '{a[$1]=($1 in a)?a[$1] OFS $3:$3}END{for(i in a) print i,a[i]}' OFS='\t' myFile
Showing results 1 to 16 of 16

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