Search Results

Search: Posts Made By: machomaddy
1,351
Posted By Jotne
Is this a typo? Shorten the solution krishmaths...
Is this a typo?
Shorten the solution krishmaths posted.
(no need to test for txt, since txt is what we replace)

awk '/\$Bad.*(GTS|JER)/ {gsub(/.txt/, ".log")} 1' file
abcdefghi
jklmnop
...
1,351
Posted By krishmaths
awk '/\$Bad/&&(/GTS/||/JER/||/REJ/)&&/txt/...
awk '/\$Bad/&&(/GTS/||/JER/||/REJ/)&&/txt/ {gsub(/.txt/, ".log")} 1' infile
1,833
Posted By PikK45
All this could have been done in a single...
All this could have been done in a single command.. No need of echo, 3-4 awk and while loops :(


awk -F"|" 'NR>2 { print "Processing "$0; print $1;}' file
1,833
Posted By Don Cragun
Of course, I agree. I assumed machomaddy...
Of course, I agree.

I assumed machomaddy plans to perform other processing on each (non-header) line of an input file and that the second awk was a placeholder for some other processing.

If all...
1,699
Posted By Scrutinizer
Try: while IFS= read -r i
Try:
while IFS= read -r i
2,635
Posted By Corona688
You agreed not to bump posts when you registered....
You agreed not to bump posts when you registered. Please stop doing it. We are not "on call"; if someone doesn't answer your post immediately, wait!

What exactly do you want? Do you need to...
2,635
Posted By bartus11
awk -F"|" -v OFS="|" 'NR==FNR{a[$0];next}$3 in...
awk -F"|" -v OFS="|" 'NR==FNR{a[$0];next}$3 in a{$3=""}$4 in a{$4=""}1' file2 file1
2,635
Posted By Scrutinizer
Try: awk 'NR==FNR{A[$1];next}$3 in A{$3=x}$4 in...
Try:
awk 'NR==FNR{A[$1];next}$3 in A{$3=x}$4 in A{$4=x}1' file2 FS=\| OFS=\| file1
20,052
Posted By tukuyomi
Another awk solution: ~/unix.com$ awk '{OFS="";...
Another awk solution:
~/unix.com$ awk '{OFS=""; S=""; i=start-1; while(i++<end){S=S OFS $i;OFS=FS}}$0=S' start=3 end=99 FS='|' file
Set start and end at the end of the line to match your...
10,564
Posted By Corona688
The "3|4" is the list of fields you want to...
The "3|4" is the list of fields you want to replace here. It's split() into the array F so that F[1]=3, F[2]=4, using the same separator as everything else... Then we loop over that array, for(N in...
4,030
Posted By Scrutinizer
Try: awk '/^[0-9]*,/{if(p)print p; p=$0;...
Try:
awk '/^[0-9]*,/{if(p)print p; p=$0; next}{p=p$0}END{print p}' infile
4,030
Posted By durden_tyler
$ $ cat -n f56 1 1,nmae,lctn,da ...
$
$ cat -n f56
1 1,nmae,lctn,da
2 t
3 2,ghjik,o
4 ut,de
5 fk
$
$ perl -ne 'chomp; print "\n" if /^\d/ && $.>1; printf; END{print "\n"}' f56
1,nmae,lctn,dat...
4,069
Posted By rdcwayx
awk '{s=$1 FS $2 FS $3} ...
awk '{s=$1 FS $2 FS $3}
NR==FNR{a[s]++;b[s]=FNR;next}
FNR==1{print;next}
{if (a[s]<2)
{print}
else
{print (b[s]==FNR)?$0 "|C":$0 "|D"}}' FS=\|...
3,184
Posted By Scrutinizer
Alternatively: awk -F\| 'NR==FNR{A[$1]=1;next}...
Alternatively:
awk -F\| 'NR==FNR{A[$1]=1;next} NR==1 || !A[$1]' file2 file1
-or-
in bash:
grep -vf <(sed '1d;s/^/^/' file2) file1
1,391
Posted By Franklin52
Try: awk -F"|" '!(index($4," ")){$4=$4 "...
Try:
awk -F"|" '!(index($4," ")){$4=$4 " 00:00:00"}1' OFS="|" file
23,272
Posted By methyl
Much faster with "sed". Also by using "while...
Much faster with "sed". Also by using "while read" rather than "for" we preserve each record intact:
sed -n '2,$ p' test.txt | while read line
do
echo "${line}"
done
Note the double...
23,272
Posted By Corona688
or awk: awk 'NR>8' file | while read LINE ...
or awk:

awk 'NR>8' file | while read LINE
do
...
done
Also see useless use of cat (http://partmaps.org/era/unix/award.html) and useless use of backticks...
1,458
Posted By cfajohnson
Why close it? You may get other useful or more...
Why close it? You may get other useful or more optimum answers.

For example, in bash4 you can use parameter expansion to make it case-insensitive:

case ${procnam,,} in
admission ) nf=65 ;;...
1,458
Posted By Scrutinizer
How about: case $procnam in admission )...
How about:

case $procnam in
admission ) nf=65 ;;
reporting ) nf=46 ;;
transfer ) nf=164 ;;
diagnosis ) nf=545 ;;
emergency ) nf=56 ;;
inpatient ) nf=37 ;;
esac

To make...
7,901
Posted By Android Control
Be careful with your expectations, as your...
Be careful with your expectations, as your results will actually be;

1 4
2 4
3 4

Even though the first two lines have nothing after the last "|" there will still be a count of 4 for each...
1,714
Posted By bartus11
Try: awk -F, -vOFS=","...
Try: awk -F, -vOFS="," 'NF<4{f=f""$0;n=split(f,a,",");if (n==4){print f;f=""}}NF==4' file
7,901
Posted By bartus11
awk -F '|' '{print NR,NF}'
awk -F '|' '{print NR,NF}'
14,392
Posted By Scrutinizer
OK, I presume you mean the first awk. ...
OK, I presume you mean the first awk.

NR%2|On every odd record. Because a double quote is used as a record separator, every odd record is outside the double quotes and every even record is within...
14,392
Posted By Scrutinizer
You could first transform the file into a ;...
You could first transform the file into a ; delimited file, for example and remove the double quotes. Then you could extract the field in a separate awk:
$ echo '1,"aa,b",4' | awk...
33,571
Posted By Scrutinizer
Hi, normally you should start a new thread for...
Hi, normally you should start a new thread for that...
Try: sed 's/[^,]$/&,/'file
Showing results 1 to 25 of 32

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