Search Results

Search: Posts Made By: apenkov
2,612
Posted By nezabudka
Hi try so $(10) $(11) and so on (in awk) ...
Hi
try so
$(10) $(11) and so on (in awk)
${10} ${11} (in bash script)
22,196
Posted By RudiC
Given the substring lengths are found in a file...
Given the substring lengths are found in a file structured like above, and an empty field separator splits a line into single characters,try
awk '
NR == FNR {P[MX = NR] = $2
...
22,196
Posted By rbatte1
Okay, so you can use variable substitution to...
Okay, so you can use variable substitution to slice up the variables in the current shell, i.e. you don't need to call cut etc.

If you know the field lengths are fixed, then perhaps something like...
2,336
Posted By RudiC
What's your OS, shell, and awk version?
What's your OS, shell, and awk version?
2,336
Posted By RavinderSingh13
Hello apenkov, As you haven't told us...
Hello apenkov,

As you haven't told us your O.S which you are using, so if you are on a Solaris/SunOS system, change awkto /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk. Because when I tried...
1,378
Posted By RavinderSingh13
Hello apenkov, Following may help you in...
Hello apenkov,

Following may help you in same.

awk '{print $1 OFS $3 OFS $5}' FIELDWIDTHS="5 7 17 10 12" Input_file
Output will be as follows.

12345 12345671234567 1234567
12345 ...
1,378
Posted By RudiC
Tryawk 'NF==5{$3=substr($3,1,7) " " substr($3,8);...
Tryawk 'NF==5{$3=substr($3,1,7) " " substr($3,8); $0=$0} {print $1,$3,$4, $6}' file
12345 1234567 1234567 1234567
12345 123456 1234567 1234567
1,083
Posted By radoulov
awk -F, 'BEGIN { p="str1,str2,str3,str4" ...
awk -F, 'BEGIN {
p="str1,str2,str3,str4"
ef = ",,,,,"
n = split(p, t)
}
$1 == t[1] && NR > 1 {
for (i = 0; ++i <= n; )
printf "%s%s", (t[i] in r ? r[t[i]] : ef), (i < n ? OFS :...
2,548
Posted By Akshay Hegde
awk ' BEGIN{ num =...
awk '
BEGIN{
num = "one two three four five six seven eight nine ten"
n = split(num,A)
for(i=1;i<=n;i++)NUM[A[i]]=i
}...
1,749
Posted By Chubler_XL
Do you and a comma on the end of the line? If so...
Do you and a comma on the end of the line? If so ... remove 2nd gsub call:

awk '{gsub(/ *[\r\n]+|, /, ",");$0=RS $0} NR>1' RS='str1' infile
1,749
Posted By Chubler_XL
There is something about this input file we are...
There is something about this input file we are not seeing in your pasted example, could you attach the testing file you are using (you might have to change it's extension to .txt for the attach file...
2,548
Posted By Akshay Hegde
Using RudiC's approach awk ' ...
Using RudiC's approach

awk '
BEGIN{
num = "one two three four five six seven eight nine ten"
n = split(num,A)
...
2,548
Posted By RudiC
Try awk '/start/,/stop/ {if ($1~/^one|^three/)...
Try awk '/start/,/stop/ {if ($1~/^one|^three/) printf "start,%s,%s,%s\n", $1, $2, $3}' file
start,one,xxx,yyy
start,three,ccc,vvv
start,one,rrr,ttt
start,three,iii,ooo
2,548
Posted By RudiC
Tryawk '/start/,/stop/ {if (($1-2)^2 == 1) printf...
Tryawk '/start/,/stop/ {if (($1-2)^2 == 1) printf "start,%s,%s,%s\n", $1, $2, $3}' file
start,1,xxx,yyy
start,3,ccc,vvv
start,1,rrr,ttt
start,3,iii,ooo
1,675
Posted By disedorgue
Or: $ ls file1.txt.gz file2.txt.gz ...
Or:
$ ls
file1.txt.gz file2.txt.gz file3.txt.gz
$ find . -name 'file*.txt.gz' | sed 's/\(.*\)txt\(.*\)/mv -v & \1dat\2/e'
«./file1.txt.gz» -> «./file1.dat.gz»
«./file2.txt.gz» ->...
1,675
Posted By zaxxon
If your shell can do variable substitution and...
If your shell can do variable substitution and there is no blanks in the filenames, you can try:

$ ls -1
file1.txt.gz
file2.txt.gz
file3.txt.gz
$ for a in file*.txt.gz; do A=${a/txt/dat}; mv...
1,801
Posted By NarayanaPrakash
awk 'NR==FNR{A[$9];next}!($9 in A)' test.txt...
awk 'NR==FNR{A[$9];next}!($9 in A)' test.txt test2.txt --> change column name

above one will compare 9th column of two files and display the difference
1,801
Posted By radoulov
Try nawk or /usr/xpg4/bin/awk, instead of awk.
Try nawk or /usr/xpg4/bin/awk, instead of awk.
1,801
Posted By Yoda
awk -F, ' NR == FNR { ...
awk -F, '
NR == FNR {
A[$1]
next
}
$1 in A {
B[$1]
print
}
END {
for...
1,940
Posted By elixir_sinari
Assuming ASCII data, try perl -F, -lape 'BEGIN...
Assuming ASCII data, try
perl -F, -lape 'BEGIN { ($tmpl = shift) =~ s/(\d+)/A$1/g }
$_ = pack($tmpl, @F)' "$COLUMNS" "$indir/input_file.dat" > "$outdir/output_file.dat"
1,055
Posted By hanson44
Here is a way to change the name of the log file:...
Here is a way to change the name of the log file:

log_file=log_`date '+%Y%m%d%H'`.log
old_hour=`date '+%H'`

while sleep 10; do
new_hour=`date '+%H'`
if [ $new_hour -ne $old_hour ]; then...
7,933
Posted By RudiC
You can either gzcat *.gz to a temp directory,...
You can either gzcat *.gz to a temp directory, and run grep -l on that, or you need a for loop like for FN in *.gz; do gzcat "$FN" | grep string && echo "$FN"; done
1,166
Posted By alister
Well, if your file does actually consist of fixed...
Well, if your file does actually consist of fixed length fields, then the length of the substring extracted and the length of the string literal used for comparison should both be equal to the length...
1,166
Posted By Corona688
You don't need to use substrings, awk can handle...
You don't need to use substrings, awk can handle columns all on its own.
awk '$2 == "140"' inputfile
1,169
Posted By radoulov
EDIT: The above solution involves external...
EDIT: The above solution involves external commands and in this case it could be avoided.

You could get rid of the files array by using the code below:
shopt -s nullglob
while :; do
set --...
Showing results 1 to 25 of 38

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