Search Results

Search: Posts Made By: palex
2,923
Posted By vgersh99
how about: awk '{print $1,...
how about:

awk '{print $1, substr($1,length($1)-1)}' OFS='\t' myInputFile
4,025
Posted By nezabudka
I understood awk -F"<[^>]*>" '/b244/ {cn++;...
I understood
awk -F"<[^>]*>" '/b244/ {cn++; if(cn == 2) printf $2}; /b203/ {printf "\t" $2}; /j151/ {cn=0; print "\t" $2}' file

--- Post updated at 21:48 ---

sed -n '
/b244/! b; x;s/$/\n/...
Forum: OS X (Apple) 05-05-2018
3,356
Posted By Scrutinizer
Try: grep -f <(pbpaste) file or grep...
Try:
grep -f <(pbpaste) file
or
grep "$(pbpaste)" file





--
Note: some greps can also do this:pbpaste | grep -f - file, but not MacOS' BSD grep.
1,129
Posted By drl
Hi. If the input files are sorted on the...
Hi.

If the input files are sorted on the fields to be matched, then one can use:
join [options] <files>
like this:
#!/usr/bin/env bash

# @(#) s1 Demonstrate blending matched-field...
1,129
Posted By RudiC
Try, then, awk 'FNR==NR{A[$1]=$2;next} ($NF in...
Try, then,
awk 'FNR==NR{A[$1]=$2;next} ($NF in A){print $0,A[$NF]}' file1 file2
col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 2222 0.35
col1 col2 col3 col4 col5 col6 col7 col8 col9 col10...
1,129
Posted By RavinderSingh13
Hello palex, Could you please try following...
Hello palex,

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

awk 'FNR==NR{A[$1]=$0;next} ($NF in A){print $0,A[$NF]}' Input_file1 Input_file2
Thanks,
R. Singh
1,249
Posted By Don Cragun
You're close. You can use two arrays instead of...
You're close. You can use two arrays instead of just one... Try:
awk '
FNR == NR {
v[$1] = $4
v2[$1] = $7
next
}
$1 in v {
print $0, v[$1], v2[$1]
}' OFS="\t" file2 file1
Or, since...
1,249
Posted By Don Cragun
Try something like: awk ' FNR == NR { ...
Try something like:
awk '
FNR == NR {
v[$1] = $4
next
}
$1 in v {
print $0, v[$1]
}' OFS="\t" file2 file1
I don't know about XQuartz, but it works fine in a Terminal window.
Forum: UNIX and Linux Applications 03-14-2017
37,388
Posted By drl
Hi, palex. You need to have xml2 in your...
Hi, palex.

You need to have xml2 in your system. As I wrote, it is available for installing in at least the version of MacOS that I have, albeit from 3rd parties.

If the solution from RudiC...
1,190
Posted By Don Cragun
Try: grep -Eo '978[0-9]{10}' datafile
Try:
grep -Eo '978[0-9]{10}' datafile
1,588
Posted By drl
Hi. -d, --dictionary-order ...
Hi.
-d, --dictionary-order
consider only blanks and alphanumeric characters

-- man sort
From your sample input file:
Input data file data1:
xxx 12345 Rat in the house...
1,588
Posted By Don Cragun
You could try something like: tmpfile="NC$$" ...
You could try something like:
tmpfile="NC$$"
> "$tmpfile"
awk -v f="$tmpfile" '
match($3, /[^[:upper:]]/) {
print > f
next
}
1' file
cat "$tmpfile"
rm -f "$tmpfile"
If you want to try...
2,226
Posted By senhia83
Only works if you have only AS and AOD in col4......
Only works if you have only AS and AOD in col4...


$ cat tmp
9780020080954 9.95 0.49 AS 23.3729
9780020130857 9.95 0.49 AS 23.3729
9780023001406 22.20 0.25 AOD 42.4725
9780023008207...
902
Posted By RudiC
Adapting Akshay Hegde's second proposal:awk -F'|'...
Adapting Akshay Hegde's second proposal:awk -F'|' '{if (substr (A[$1],length(A[$1])-2) != "NET") A[$1]=$0}END{for(i in A)print A[i]}' file
902
Posted By Akshay Hegde
akshay@Aix:/tmp$ cat file 345234|22.34|LST ...
akshay@Aix:/tmp$ cat file
345234|22.34|LST
546543|55.33|LST
793929|98.23|LST
793929|64.69|NET
149593|49.22|LST

akshay@Aix:/tmp$ awk -F'|' 'FNR==NR{A[$1]=$0;next}($1 in A){print A[$1];delete...
1,012
Posted By Yoda
Here is an awk approach: awk ' { ...
Here is an awk approach:
awk '
{
if ( A[$1] > $2 || !(A[$1]) )
A[$1] = $2
}
END {
for ( k in A )
...
1,048
Posted By spacebar
This doesn't validate if you actually have an...
This doesn't validate if you actually have an element in the 3rd position from the end, One example:
$ declare -a array=( 1 2 3 4 5 6)
$ c=${#arrray[@]}; e=$c-3; echo ${array[$e]}
4
1,048
Posted By MadeInGermany
awk -F, '{print $(NF-2)}' file.dat
awk -F, '{print $(NF-2)}' file.dat
1,479
Posted By Yoda
awk '{ for(i=1;i<=NF;i++) if($i ~ /^123/) print...
awk '{ for(i=1;i<=NF;i++) if($i ~ /^123/) print $i; }' file
4,079
Posted By raj_saini20
here is modified pravin27's code awk...
here is modified pravin27's code

awk 'NR==FNR{f1=substr($0,1,index($0,".")-1);a[f1]=$0;next}
{if(a[$1]){print $2,$3,$4,a[$1]}else{print $2,$3,$4,"none.gif"}}' file2 file1
4,079
Posted By elixir_sinari
awk...
awk 'FNR==NR{a[$1]=$0;next}{$(NF+1)=a[$1]?a[$1]:"none.gif";$1=""}1' FS='[.]' sourcefile2.dat FS=' ' sourcefile1.dat
4,079
Posted By pravin27
awk...
awk 'NR==FNR{f1=substr($0,1,index($0,".")-1);a[f1]=$0;next}
a[$1]{print $2,$3,$4,a[$1]}' file2 file1
4,079
Posted By vgersh99
awk...
awk 'FNR==NR{f2[$1];next}{a=$1;sub("^[^"FS"]*"FS,"");print $0, ((a in f2)?a:"none") ".gif"}' FS=. file2.txt FS=' ' file1.txt
2,231
Posted By Scott
There is no space between < and (
There is no space between < and (
1,910
Posted By joeyg
Here is another approach
$ cat p1.txt
1234 5
2345 3
3456 67
4567 21
5678 9
6789 22
7890 54

$ cat p2.txt
zzzz,'3456',xxx
zzzz,'2345',xxx
zzzz,'6789',xxx

$ cut -d, -f2 <p2.txt | tr -d "'" >p2a.txt


$ grep...
Showing results 1 to 25 of 35

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