Search Results

Search: Posts Made By: radius
921
Posted By RavinderSingh13
Hello radius, Could you please try following...
Hello radius,

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

awk 'FNR==1{split(FILENAME, array,"_");sub(/\.txt/,"",array[2]);} {print array[1]"|"$0"|"array[2]}'...
25,614
Posted By Don Cragun
The first double-quote character on the line: ...
The first double-quote character on the line:
SCRIPT_NAME=“test";
is the wrong character. Change that line to:
SCRIPT_NAME="test";
and try again.
2,001
Posted By RavinderSingh13
Hello Radius, Following may help you in...
Hello Radius,

Following may help you in same.

awk -F"|" #### Taking pipe | as a delimiter
'FNR==NR #### putting a condition where FNR==NR which will be TRUE only...
2,001
Posted By RavinderSingh13
Hello radius, Good try from you, and thanks...
Hello radius,

Good try from you, and thanks for showing us what you have tried so far. You can use following for your requirement. Let me know if you have any queries on same.

awk -F"|"...
1,507
Posted By Scrutinizer
Try: awk -F'|' 'NR==FNR {h[$1] = $2; next}...
Try:
awk -F'|' 'NR==FNR {h[$1] = $2; next} {FS=OFS="|";print $0,h[$3]}' file2 file1
or (no need to set FS and OFS on every line):
awk -F'|' -v OFS='|' 'NR==FNR {h[$1] = $2; next} {print $0,h[$3]}'...
903
Posted By RudiC
You were aiming in the right direction. Try awk...
You were aiming in the right direction. Try awk -F'|' 'NR==FNR {h[$1]=1; next} {print $0, h[$1]+0}' OFS="|" file2 file1
0912804166|RR|1
0912804171|YY|0
756
Posted By Don Cragun
You could also try the slightly simpler: awk -F...
You could also try the slightly simpler:
awk -F '|' 'FNR==NR{a[$1];next}$3 in a' file1.txt file2.txt
Note that the order of the file arguments is reversed when compared to the script...
1,836
Posted By Akshay Hegde
OR try something like this [akshay@localhost...
OR try something like this

[akshay@localhost tmp]$ cat infile
USA|80
AUS|40
BRA|33

VEGAS|40
KENTUCKY|50
NEWYORK|21
DARWIN|33
ADELAIDE|21
SAOPAOLO|44
RIO|89
GAPIZA|44
BENFLEX|32
...
1,836
Posted By RavinderSingh13
Hello radius, Following is the...
Hello radius,

Following is the explaination.

if($1 ~ /USA/ || $1 ~ /VEGAS/ || $1 ~ /KENTUCKY/ || $1 ~ /NEWYORK/ || $1 ~ /AXIS/ || $1 ~ /ACRE/){A=A?A OFS $0:$0}
If $1 is equal to USA or VEGAS...
1,605
Posted By RudiC
Try awk 'NR==1 {split ($0, D)} ...
Try awk 'NR==1 {split ($0, D)}
NR>1 {for (i=7; i<=NF; i++) print $1,$2,$3,$4,$5,$6, D[i], $i}
' FS="|" OFS="|" file
India|Calcuta|New...
1,176
Posted By Akshay Hegde
Try awk 'NR==FNR{ h[$1] =( $1 in h ) ?...
Try

awk 'NR==FNR{
h[$1] =( $1 in h ) ? h[$1] OFS $2 : $2
next
}
{
if(split(h[$1],part,OFS)>1)
{
for(i in part)
{
print $0 OFS part[i]
}...
1,098
Posted By RavinderSingh13
Hi Radius, Following may help in same. ...
Hi Radius,

Following may help in same.

awk -F"|" -vvar=$(date +"%Y-%m") '{V=$5;gsub(/...$/,X,V);if(V == var) {print $0}}' OFS="|" Input_file


Output will be as follows.
...
1,098
Posted By Akshay Hegde
if you want to exclude line other than current...
if you want to exclude line other than current month you can do like this

awk '$2 == mon' FS='-' mon="$(date +"%m")" file
awk 'substr($5,6,2) == mon' FS='|' mon="$(date +"%m")" file

For...
1,169
Posted By Akshay Hegde
I calculated max date first and then substituted...
I calculated max date first and then substituted to field1, as you can see I am reading file twice.
1,169
Posted By Akshay Hegde
Ok you tried something... try this $ awk...
Ok you tried something... try this

$ awk 'FNR==NR{if($1 > m) m = $1 ; next}{$1 = m}1' FS='|' OFS='|' file file
979
Posted By Akshay Hegde
$ awk 'FNR==1{gsub(/.*_|\..*/,"",FILENAME)}{$0 =...
$ awk 'FNR==1{gsub(/.*_|\..*/,"",FILENAME)}{$0 = FILENAME OFS $0}1' OFS='|' *.xls
979
Posted By SriniShoo
awk 'FNR == 1 {nm=substr(FILENAME,...
awk 'FNR == 1 {nm=substr(FILENAME, length(FILENAME)-11, 8)} {print nm "|" $0}' *.xls
1,306
Posted By Don Cragun
Yes. If there is a chance that the first field...
Yes. If there is a chance that the first field could contain any characters that are special in an extended regular expression, you would need to not only change: sub($1,x) to: $1=x, but also to...
1,306
Posted By Don Cragun
Reformattig Franklin52's code and adding...
Reformattig Franklin52's code and adding comments:
awk -F\| ' # Set input field separator to "|".
fNR==FNR{ # For all lines in the 1st file given...
i=$1 # Set i to the contents of the 1st...
1,306
Posted By Franklin52
Try this: awk -F\| 'NR==FNR{i=$1;sub($1,x);...
Try this:
awk -F\| 'NR==FNR{i=$1;sub($1,x); a[i]=$0; next} $1 in a{print $0 a[$1]}' input2.txt input1.txt
1,076
Posted By RudiC
Well, I thought about that after having posted;...
Well, I thought about that after having posted; but the "|" needs to be escaped as Scrutinizer did it.
1,076
Posted By Scrutinizer
@RudiC: Unless the length is always <=5 digits,...
@RudiC: Unless the length is always <=5 digits, it would be better to include a \| as an anchor at the back...
1,076
Posted By Don Cragun
This is fine if the 5th field is always 5 or...
This is fine if the 5th field is always 5 or fewer characters. If there could be more than 5 characters in that field, you'd want an additional field separator at the end of the ERE:
grep -E...
1,076
Posted By RavinderSingh13
Hello, One more approach with awk using...
Hello,

One more approach with awk using variables.


awk -F"|" '$5==s1 || $5==s2 {print}' s1="13127" s2="13140" filename


Output will be as follows.

...
1,076
Posted By RudiC
Try grep:grep -E "^([^|]*\|){4}(13127|13140)"...
Try grep:grep -E "^([^|]*\|){4}(13127|13140)" file
Showing results 1 to 25 of 51

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